* expr.h (array_at_struct_end_p): Move to...
[official-gcc.git] / gcc / ada / par-ch9.adb
blobd2aeb5a797a23cebd55e202bc4179d521c8aa827
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-2013, Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
26 pragma Style_Checks (All_Checks);
27 -- Turn off subprogram body ordering check. Subprograms are in order by RM
28 -- section rather than alphabetical.
30 separate (Par)
31 package body Ch9 is
33 -- Local subprograms, used only in this chapter
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;
49 -----------------------------
50 -- 9.1 Task (also 10.1.3) --
51 -----------------------------
53 -- TASK_TYPE_DECLARATION ::=
54 -- task type DEFINING_IDENTIFIER [KNOWN_DISCRIMINANT_PART]
55 -- [ASPECT_SPECIFICATIONS]
56 -- [is [new INTERFACE_LIST with] TASK_DEFINITION];
58 -- SINGLE_TASK_DECLARATION ::=
59 -- task DEFINING_IDENTIFIER
60 -- [ASPECT_SPECIFICATIONS]
61 -- [is [new INTERFACE_LIST with] TASK_DEFINITION];
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]
70 -- TASK_BODY_STUB ::=
71 -- task body DEFINING_IDENTIFIER is separate
72 -- [ASPECT_SPECIFICATIONS];
74 -- This routine scans out a task declaration, task body, or task stub
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
79 -- Error recovery: cannot raise Error_Resync
81 function P_Task return Node_Id is
82 Aspect_Sloc : Source_Ptr;
83 Name_Node : Node_Id;
84 Task_Node : Node_Id;
85 Task_Sloc : Source_Ptr;
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.
92 begin
93 Push_Scope_Stack;
94 Scope.Table (Scope.Last).Etyp := E_Name;
95 Scope.Table (Scope.Last).Ecol := Start_Column;
96 Scope.Table (Scope.Last).Sloc := Token_Ptr;
97 Scope.Table (Scope.Last).Lreq := False;
98 Task_Sloc := Prev_Token_Ptr;
100 if Token = Tok_Body then
101 Scan; -- past BODY
102 Name_Node := P_Defining_Identifier (C_Is);
103 Scope.Table (Scope.Last).Labl := Name_Node;
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;
110 if Aspect_Specifications_Present then
111 Aspect_Sloc := Token_Ptr;
112 P_Aspect_Specifications (Dummy_Node, Semicolon => False);
113 end if;
115 TF_Is;
117 -- Task stub
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);
124 if Has_Aspects (Dummy_Node) then
125 Error_Msg
126 ("aspect specifications must come after SEPARATE",
127 Aspect_Sloc);
128 end if;
130 P_Aspect_Specifications (Task_Node, Semicolon => False);
131 TF_Semicolon;
132 Pop_Scope_Stack; -- remove unused entry
134 -- Task body
136 else
137 Task_Node := New_Node (N_Task_Body, Task_Sloc);
138 Set_Defining_Identifier (Task_Node, Name_Node);
140 -- Move the aspect specifications to the body node
142 if Has_Aspects (Dummy_Node) then
143 Move_Aspects (From => Dummy_Node, To => Task_Node);
144 end if;
146 Parse_Decls_Begin_End (Task_Node);
148 -- The statement list of a task body needs to include at least a
149 -- null statement, so if a parsing error produces an empty list,
150 -- patch it now.
152 if No (First (Statements
153 (Handled_Statement_Sequence (Task_Node))))
154 then
155 Set_Statements (Handled_Statement_Sequence (Task_Node),
156 New_List (Make_Null_Statement (Token_Ptr)));
157 end if;
158 end if;
160 return Task_Node;
162 -- Otherwise we must have a task declaration
164 else
165 if Token = Tok_Type then
166 Scan; -- past TYPE
167 Task_Node := New_Node (N_Task_Type_Declaration, Task_Sloc);
168 Name_Node := P_Defining_Identifier;
169 Set_Defining_Identifier (Task_Node, Name_Node);
170 Scope.Table (Scope.Last).Labl := Name_Node;
171 Set_Discriminant_Specifications
172 (Task_Node, P_Known_Discriminant_Part_Opt);
174 else
175 Task_Node := New_Node (N_Single_Task_Declaration, Task_Sloc);
176 Name_Node := P_Defining_Identifier (C_Is);
177 Set_Defining_Identifier (Task_Node, Name_Node);
178 Scope.Table (Scope.Last).Labl := Name_Node;
180 if Token = Tok_Left_Paren then
181 Error_Msg_SC ("discriminant part not allowed for single task");
182 Discard_Junk_List (P_Known_Discriminant_Part_Opt);
183 end if;
184 end if;
186 -- Scan aspect specifications, don't eat the semicolon, since it
187 -- might not be there if we have an IS.
189 P_Aspect_Specifications (Task_Node, Semicolon => False);
191 -- Parse optional task definition. Note that P_Task_Definition scans
192 -- out the semicolon and possible aspect specifications as well as
193 -- the task definition itself.
195 if Token = Tok_Semicolon then
197 -- A little check, if the next token after semicolon is Entry,
198 -- then surely the semicolon should really be IS
200 Scan; -- past semicolon
202 if Token = Tok_Entry then
203 Error_Msg_SP -- CODEFIX
204 ("|"";"" should be IS");
205 Set_Task_Definition (Task_Node, P_Task_Definition);
206 else
207 Pop_Scope_Stack; -- Remove unused entry
208 end if;
210 -- Here we have a task definition
212 else
213 TF_Is; -- must have IS if no semicolon
215 -- Ada 2005 (AI-345)
217 if Token = Tok_New then
218 Scan; -- past NEW
220 if Ada_Version < Ada_2005 then
221 Error_Msg_SP ("task interface is an Ada 2005 extension");
222 Error_Msg_SP ("\unit must be compiled with -gnat05 switch");
223 end if;
225 Set_Interface_List (Task_Node, New_List);
227 loop
228 Append (P_Qualified_Simple_Name, Interface_List (Task_Node));
229 exit when Token /= Tok_And;
230 Scan; -- past AND
231 end loop;
233 if Token /= Tok_With then
234 Error_Msg_SC -- CODEFIX
235 ("WITH expected");
236 end if;
238 Scan; -- past WITH
240 if Token = Tok_Private then
241 Error_Msg_SP -- CODEFIX
242 ("PRIVATE not allowed in task type declaration");
243 end if;
244 end if;
246 Set_Task_Definition (Task_Node, P_Task_Definition);
247 end if;
249 return Task_Node;
250 end if;
251 end P_Task;
253 --------------------------------
254 -- 9.1 Task Type Declaration --
255 --------------------------------
257 -- Parsed by P_Task (9.1)
259 ----------------------------------
260 -- 9.1 Single Task Declaration --
261 ----------------------------------
263 -- Parsed by P_Task (9.1)
265 --------------------------
266 -- 9.1 Task Definition --
267 --------------------------
269 -- TASK_DEFINITION ::=
270 -- {TASK_ITEM}
271 -- [private
272 -- {TASK_ITEM}]
273 -- end [task_IDENTIFIER];
275 -- The caller has already made the scope stack entry
277 -- Note: there is a small deviation from official syntax here in that we
278 -- regard the semicolon after end as part of the Task_Definition, and in
279 -- the official syntax, it's part of the enclosing declaration. The reason
280 -- for this deviation is that otherwise the end processing would have to
281 -- be special cased, which would be a nuisance.
283 -- Error recovery: cannot raise Error_Resync
285 function P_Task_Definition return Node_Id is
286 Def_Node : Node_Id;
288 begin
289 Def_Node := New_Node (N_Task_Definition, Token_Ptr);
290 Set_Visible_Declarations (Def_Node, P_Task_Items);
292 if Token = Tok_Private then
293 Scan; -- past PRIVATE
294 Set_Private_Declarations (Def_Node, P_Task_Items);
296 -- Deal gracefully with multiple PRIVATE parts
298 while Token = Tok_Private loop
299 Error_Msg_SC ("only one private part allowed per task");
300 Scan; -- past PRIVATE
301 Append_List (P_Task_Items, Private_Declarations (Def_Node));
302 end loop;
303 end if;
305 End_Statements (Def_Node);
306 return Def_Node;
307 end P_Task_Definition;
309 --------------------
310 -- 9.1 Task Item --
311 --------------------
313 -- TASK_ITEM ::= ENTRY_DECLARATION | REPRESENTATION_CLAUSE
315 -- This subprogram scans a (possibly empty) list of task items and pragmas
317 -- Error recovery: cannot raise Error_Resync
319 -- Note: a pragma can also be returned in this position
321 function P_Task_Items return List_Id is
322 Items : List_Id;
323 Item_Node : Node_Id;
324 Decl_Sloc : Source_Ptr;
326 begin
327 -- Get rid of active SIS entry from outer scope. This means we will
328 -- miss some nested cases, but it doesn't seem worth the effort. See
329 -- discussion in Par for further details
331 SIS_Entry_Active := False;
333 -- Loop to scan out task items
335 Items := New_List;
337 Decl_Loop : loop
338 Decl_Sloc := Token_Ptr;
340 if Token = Tok_Pragma then
341 Append (P_Pragma, Items);
343 -- Ada 2005 (AI-397): Reserved words NOT and OVERRIDING
344 -- may begin an entry declaration.
346 elsif Token = Tok_Entry
347 or else Token = Tok_Not
348 or else Token = Tok_Overriding
349 then
350 Append (P_Entry_Declaration, Items);
352 elsif Token = Tok_For then
353 -- Representation clause in task declaration. The only rep
354 -- clause which is legal in a protected is an address clause,
355 -- so that is what we try to scan out.
357 Item_Node := P_Representation_Clause;
359 if Nkind (Item_Node) = N_At_Clause then
360 Append (Item_Node, Items);
362 elsif Nkind (Item_Node) = N_Attribute_Definition_Clause
363 and then Chars (Item_Node) = Name_Address
364 then
365 Append (Item_Node, Items);
367 else
368 Error_Msg
369 ("the only representation clause " &
370 "allowed here is an address clause!", Decl_Sloc);
371 end if;
373 elsif Token = Tok_Identifier
374 or else Token in Token_Class_Declk
375 then
376 Error_Msg_SC ("illegal declaration in task definition");
377 Resync_Past_Semicolon;
379 else
380 exit Decl_Loop;
381 end if;
382 end loop Decl_Loop;
384 return Items;
385 end P_Task_Items;
387 --------------------
388 -- 9.1 Task Body --
389 --------------------
391 -- Parsed by P_Task (9.1)
393 ----------------------------------
394 -- 9.4 Protected (also 10.1.3) --
395 ----------------------------------
397 -- PROTECTED_TYPE_DECLARATION ::=
398 -- protected type DEFINING_IDENTIFIER [KNOWN_DISCRIMINANT_PART]
399 -- [ASPECT_SPECIFICATIONS]
400 -- is [new INTERFACE_LIST with] PROTECTED_DEFINITION;
402 -- SINGLE_PROTECTED_DECLARATION ::=
403 -- protected DEFINING_IDENTIFIER
404 -- [ASPECT_SPECIFICATIONS]
405 -- is [new INTERFACE_LIST with] PROTECTED_DEFINITION;
407 -- PROTECTED_BODY ::=
408 -- protected body DEFINING_IDENTIFIER
409 -- [ASPECT_SPECIFICATIONS]
410 -- is
411 -- {PROTECTED_OPERATION_ITEM}
412 -- end [protected_IDENTIFIER];
414 -- PROTECTED_BODY_STUB ::=
415 -- protected body DEFINING_IDENTIFIER is separate
416 -- [ASPECT_SPECIFICATIONS];
418 -- This routine scans out a protected declaration, protected body
419 -- or a protected stub.
421 -- The caller has checked that the initial token is PROTECTED and
422 -- scanned past it, so Token is set to the following token.
424 -- Error recovery: cannot raise Error_Resync
426 function P_Protected return Node_Id is
427 Aspect_Sloc : Source_Ptr;
428 Name_Node : Node_Id;
429 Protected_Node : Node_Id;
430 Protected_Sloc : Source_Ptr;
431 Scan_State : Saved_Scan_State;
433 Dummy_Node : constant Node_Id := New_Node (N_Protected_Body, Token_Ptr);
434 -- Placeholder node used to hold legal or prematurely declared aspect
435 -- specifications. Depending on the context, the aspect specifications
436 -- may be moved to a new node.
438 begin
439 Push_Scope_Stack;
440 Scope.Table (Scope.Last).Etyp := E_Name;
441 Scope.Table (Scope.Last).Ecol := Start_Column;
442 Scope.Table (Scope.Last).Lreq := False;
443 Protected_Sloc := Prev_Token_Ptr;
445 if Token = Tok_Body then
446 Scan; -- past BODY
447 Name_Node := P_Defining_Identifier (C_Is);
448 Scope.Table (Scope.Last).Labl := Name_Node;
450 if Token = Tok_Left_Paren then
451 Error_Msg_SC ("discriminant part not allowed in protected body");
452 Discard_Junk_List (P_Known_Discriminant_Part_Opt);
453 end if;
455 if Aspect_Specifications_Present then
456 Aspect_Sloc := Token_Ptr;
457 P_Aspect_Specifications (Dummy_Node, Semicolon => False);
458 end if;
460 TF_Is;
462 -- Protected stub
464 if Token = Tok_Separate then
465 Scan; -- past SEPARATE
467 Protected_Node := New_Node (N_Protected_Body_Stub, Protected_Sloc);
468 Set_Defining_Identifier (Protected_Node, Name_Node);
470 if Has_Aspects (Dummy_Node) then
471 Error_Msg
472 ("aspect specifications must come after SEPARATE",
473 Aspect_Sloc);
474 end if;
476 P_Aspect_Specifications (Protected_Node, Semicolon => False);
477 TF_Semicolon;
478 Pop_Scope_Stack; -- remove unused entry
480 -- Protected body
482 else
483 Protected_Node := New_Node (N_Protected_Body, Protected_Sloc);
484 Set_Defining_Identifier (Protected_Node, Name_Node);
486 Move_Aspects (From => Dummy_Node, To => Protected_Node);
487 Set_Declarations (Protected_Node, P_Protected_Operation_Items);
488 End_Statements (Protected_Node);
489 end if;
491 return Protected_Node;
493 -- Otherwise we must have a protected declaration
495 else
496 if Token = Tok_Type then
497 Scan; -- past TYPE
498 Protected_Node :=
499 New_Node (N_Protected_Type_Declaration, Protected_Sloc);
500 Name_Node := P_Defining_Identifier (C_Is);
501 Set_Defining_Identifier (Protected_Node, Name_Node);
502 Scope.Table (Scope.Last).Labl := Name_Node;
503 Set_Discriminant_Specifications
504 (Protected_Node, P_Known_Discriminant_Part_Opt);
506 else
507 Protected_Node :=
508 New_Node (N_Single_Protected_Declaration, Protected_Sloc);
509 Name_Node := P_Defining_Identifier (C_Is);
510 Set_Defining_Identifier (Protected_Node, Name_Node);
512 if Token = Tok_Left_Paren then
513 Error_Msg_SC
514 ("discriminant part not allowed for single protected");
515 Discard_Junk_List (P_Known_Discriminant_Part_Opt);
516 end if;
518 Scope.Table (Scope.Last).Labl := Name_Node;
519 end if;
521 P_Aspect_Specifications (Protected_Node, Semicolon => False);
523 -- Check for semicolon not followed by IS, this is something like
525 -- protected type r;
527 -- where we want
529 -- protected type r IS END;
531 if Token = Tok_Semicolon then
532 Save_Scan_State (Scan_State); -- at semicolon
533 Scan; -- past semicolon
535 if Token /= Tok_Is then
536 Restore_Scan_State (Scan_State);
537 Error_Msg_SC -- CODEFIX
538 ("missing IS");
539 Set_Protected_Definition (Protected_Node,
540 Make_Protected_Definition (Token_Ptr,
541 Visible_Declarations => Empty_List,
542 End_Label => Empty));
544 SIS_Entry_Active := False;
545 End_Statements
546 (Protected_Definition (Protected_Node), Protected_Node);
547 return Protected_Node;
548 end if;
550 Error_Msg_SP -- CODEFIX
551 ("|extra ""("" ignored");
552 end if;
554 T_Is;
556 -- Ada 2005 (AI-345)
558 if Token = Tok_New then
559 Scan; -- past NEW
561 if Ada_Version < Ada_2005 then
562 Error_Msg_SP ("protected interface is an Ada 2005 extension");
563 Error_Msg_SP ("\unit must be compiled with -gnat05 switch");
564 end if;
566 Set_Interface_List (Protected_Node, New_List);
568 loop
569 Append (P_Qualified_Simple_Name,
570 Interface_List (Protected_Node));
572 exit when Token /= Tok_And;
573 Scan; -- past AND
574 end loop;
576 if Token /= Tok_With then
577 Error_Msg_SC -- CODEFIX
578 ("WITH expected");
579 end if;
581 Scan; -- past WITH
582 end if;
584 Set_Protected_Definition (Protected_Node, P_Protected_Definition);
585 return Protected_Node;
586 end if;
587 end P_Protected;
589 -------------------------------------
590 -- 9.4 Protected Type Declaration --
591 -------------------------------------
593 -- Parsed by P_Protected (9.4)
595 ---------------------------------------
596 -- 9.4 Single Protected Declaration --
597 ---------------------------------------
599 -- Parsed by P_Protected (9.4)
601 -------------------------------
602 -- 9.4 Protected Definition --
603 -------------------------------
605 -- PROTECTED_DEFINITION ::=
606 -- {PROTECTED_OPERATION_DECLARATION}
607 -- [private
608 -- {PROTECTED_ELEMENT_DECLARATION}]
609 -- end [protected_IDENTIFIER]
611 -- PROTECTED_ELEMENT_DECLARATION ::=
612 -- PROTECTED_OPERATION_DECLARATION
613 -- | COMPONENT_DECLARATION
615 -- The caller has already established the scope stack entry
617 -- Error recovery: cannot raise Error_Resync
619 function P_Protected_Definition return Node_Id is
620 Def_Node : Node_Id;
621 Item_Node : Node_Id;
623 begin
624 Def_Node := New_Node (N_Protected_Definition, Token_Ptr);
626 -- Get rid of active SIS entry from outer scope. This means we will
627 -- miss some nested cases, but it doesn't seem worth the effort. See
628 -- discussion in Par for further details
630 SIS_Entry_Active := False;
632 -- Loop to scan visible declarations (protected operation declarations)
634 Set_Visible_Declarations (Def_Node, New_List);
636 loop
637 Item_Node := P_Protected_Operation_Declaration_Opt;
638 exit when No (Item_Node);
639 Append (Item_Node, Visible_Declarations (Def_Node));
640 end loop;
642 -- Deal with PRIVATE part (including graceful handling of multiple
643 -- PRIVATE parts).
645 Private_Loop : while Token = Tok_Private loop
646 if No (Private_Declarations (Def_Node)) then
647 Set_Private_Declarations (Def_Node, New_List);
648 else
649 Error_Msg_SC ("duplicate private part");
650 end if;
652 Scan; -- past PRIVATE
654 Declaration_Loop : loop
655 if Token = Tok_Identifier then
656 P_Component_Items (Private_Declarations (Def_Node));
657 else
658 Item_Node := P_Protected_Operation_Declaration_Opt;
659 exit Declaration_Loop when No (Item_Node);
660 Append (Item_Node, Private_Declarations (Def_Node));
661 end if;
662 end loop Declaration_Loop;
663 end loop Private_Loop;
665 End_Statements (Def_Node);
666 return Def_Node;
667 end P_Protected_Definition;
669 ------------------------------------------
670 -- 9.4 Protected Operation Declaration --
671 ------------------------------------------
673 -- PROTECTED_OPERATION_DECLARATION ::=
674 -- SUBPROGRAM_DECLARATION
675 -- | ENTRY_DECLARATION
676 -- | REPRESENTATION_CLAUSE
678 -- Error recovery: cannot raise Error_Resync
680 -- Note: a pragma can also be returned in this position
682 -- We are not currently permitting representation clauses to appear as
683 -- protected operation declarations, do we have to rethink this???
685 function P_Protected_Operation_Declaration_Opt return Node_Id is
686 L : List_Id;
687 P : Source_Ptr;
689 function P_Entry_Or_Subprogram_With_Indicator return Node_Id;
690 -- Ada 2005 (AI-397): Parse an entry or a subprogram with an overriding
691 -- indicator. The caller has checked that the initial token is NOT or
692 -- OVERRIDING.
694 ------------------------------------------
695 -- P_Entry_Or_Subprogram_With_Indicator --
696 ------------------------------------------
698 function P_Entry_Or_Subprogram_With_Indicator return Node_Id is
699 Decl : Node_Id := Error;
700 Is_Overriding : Boolean := False;
701 Not_Overriding : Boolean := False;
703 begin
704 if Token = Tok_Not then
705 Scan; -- past NOT
707 if Token = Tok_Overriding then
708 Scan; -- past OVERRIDING
709 Not_Overriding := True;
710 else
711 Error_Msg_SC -- CODEFIX
712 ("OVERRIDING expected!");
713 end if;
715 else
716 Scan; -- past OVERRIDING
717 Is_Overriding := True;
718 end if;
720 if Is_Overriding or else Not_Overriding then
721 if Ada_Version < Ada_2005 then
722 Error_Msg_SP ("overriding indicator is an Ada 2005 extension");
723 Error_Msg_SP ("\unit must be compiled with -gnat05 switch");
725 elsif Token = Tok_Entry then
726 Decl := P_Entry_Declaration;
728 Set_Must_Override (Decl, Is_Overriding);
729 Set_Must_Not_Override (Decl, Not_Overriding);
731 elsif Token = Tok_Function or else Token = Tok_Procedure then
732 Decl := P_Subprogram (Pf_Decl_Pexp);
734 Set_Must_Override (Specification (Decl), Is_Overriding);
735 Set_Must_Not_Override (Specification (Decl), Not_Overriding);
737 else
738 Error_Msg_SC -- CODEFIX
739 ("ENTRY, FUNCTION or PROCEDURE expected!");
740 end if;
741 end if;
743 return Decl;
744 end P_Entry_Or_Subprogram_With_Indicator;
746 -- Start of processing for P_Protected_Operation_Declaration_Opt
748 begin
749 -- This loop runs more than once only when a junk declaration
750 -- is skipped.
752 loop
753 if Token = Tok_Pragma then
754 return P_Pragma;
756 elsif Token = Tok_Not or else Token = Tok_Overriding then
757 return P_Entry_Or_Subprogram_With_Indicator;
759 elsif Token = Tok_Entry then
760 return P_Entry_Declaration;
762 elsif Token = Tok_Function or else Token = Tok_Procedure then
763 return P_Subprogram (Pf_Decl_Pexp);
765 elsif Token = Tok_Identifier then
766 L := New_List;
767 P := Token_Ptr;
768 Skip_Declaration (L);
770 if Nkind (First (L)) = N_Object_Declaration then
771 Error_Msg
772 ("component must be declared in private part of " &
773 "protected type", P);
774 else
775 Error_Msg
776 ("illegal declaration in protected definition", P);
777 end if;
779 elsif Token in Token_Class_Declk then
780 Error_Msg_SC ("illegal declaration in protected definition");
781 Resync_Past_Semicolon;
783 -- Return now to avoid cascaded messages if next declaration
784 -- is a valid component declaration.
786 return Error;
788 elsif Token = Tok_For then
789 Error_Msg_SC
790 ("representation clause not allowed in protected definition");
791 Resync_Past_Semicolon;
793 else
794 return Empty;
795 end if;
796 end loop;
797 end P_Protected_Operation_Declaration_Opt;
799 -----------------------------------
800 -- 9.4 Protected Operation Item --
801 -----------------------------------
803 -- PROTECTED_OPERATION_ITEM ::=
804 -- SUBPROGRAM_DECLARATION
805 -- | SUBPROGRAM_BODY
806 -- | ENTRY_BODY
807 -- | REPRESENTATION_CLAUSE
809 -- This procedure parses and returns a list of protected operation items
811 -- We are not currently permitting representation clauses to appear
812 -- as protected operation items, do we have to rethink this???
814 function P_Protected_Operation_Items return List_Id is
815 Item_List : List_Id;
817 begin
818 Item_List := New_List;
820 loop
821 if Token = Tok_Entry or else Bad_Spelling_Of (Tok_Entry) then
822 Append (P_Entry_Body, Item_List);
824 -- If the operation starts with procedure, function, or an overriding
825 -- indicator ("overriding" or "not overriding"), parse a subprogram.
827 elsif Token = Tok_Function or else Bad_Spelling_Of (Tok_Function)
828 or else
829 Token = Tok_Procedure or else Bad_Spelling_Of (Tok_Procedure)
830 or else
831 Token = Tok_Overriding or else Bad_Spelling_Of (Tok_Overriding)
832 or else
833 Token = Tok_Not or else Bad_Spelling_Of (Tok_Not)
834 then
835 Append (P_Subprogram (Pf_Decl_Pbod_Pexp), Item_List);
837 elsif Token = Tok_Pragma or else Bad_Spelling_Of (Tok_Pragma) then
838 P_Pragmas_Opt (Item_List);
840 elsif Token = Tok_Private or else Bad_Spelling_Of (Tok_Private) then
841 Error_Msg_SC ("PRIVATE not allowed in protected body");
842 Scan; -- past PRIVATE
844 elsif Token = Tok_Identifier then
845 Error_Msg_SC ("all components must be declared in spec!");
846 Resync_Past_Semicolon;
848 elsif Token in Token_Class_Declk then
849 Error_Msg_SC ("this declaration not allowed in protected body");
850 Resync_Past_Semicolon;
852 else
853 exit;
854 end if;
855 end loop;
857 return Item_List;
858 end P_Protected_Operation_Items;
860 ------------------------------
861 -- 9.5.2 Entry Declaration --
862 ------------------------------
864 -- ENTRY_DECLARATION ::=
865 -- [OVERRIDING_INDICATOR]
866 -- entry DEFINING_IDENTIFIER
867 -- [(DISCRETE_SUBTYPE_DEFINITION)] PARAMETER_PROFILE
868 -- [ASPECT_SPECIFICATIONS];
870 -- The caller has checked that the initial token is ENTRY, NOT or
871 -- OVERRIDING.
873 -- Error recovery: cannot raise Error_Resync
875 function P_Entry_Declaration return Node_Id is
876 Decl_Node : Node_Id;
877 Scan_State : Saved_Scan_State;
879 -- Flags for optional overriding indication. Two flags are needed,
880 -- to distinguish positive and negative overriding indicators from
881 -- the absence of any indicator.
883 Is_Overriding : Boolean := False;
884 Not_Overriding : Boolean := False;
886 begin
887 -- Ada 2005 (AI-397): Scan leading overriding indicator
889 if Token = Tok_Not then
890 Scan; -- past NOT
892 if Token = Tok_Overriding then
893 Scan; -- part OVERRIDING
894 Not_Overriding := True;
895 else
896 Error_Msg_SC -- CODEFIX
897 ("OVERRIDING expected!");
898 end if;
900 elsif Token = Tok_Overriding then
901 Scan; -- part OVERRIDING
902 Is_Overriding := True;
903 end if;
905 if Is_Overriding or else Not_Overriding then
906 if Ada_Version < Ada_2005 then
907 Error_Msg_SP ("overriding indicator is an Ada 2005 extension");
908 Error_Msg_SP ("\unit must be compiled with -gnat05 switch");
910 elsif Token /= Tok_Entry then
911 Error_Msg_SC -- CODEFIX
912 ("ENTRY expected!");
913 end if;
914 end if;
916 Decl_Node := New_Node (N_Entry_Declaration, Token_Ptr);
917 Scan; -- past ENTRY
919 Set_Defining_Identifier
920 (Decl_Node, P_Defining_Identifier (C_Left_Paren_Semicolon));
922 -- If left paren, could be (Discrete_Subtype_Definition) or Formal_Part
924 if Token = Tok_Left_Paren then
925 Scan; -- past (
927 -- If identifier after left paren, could still be either
929 if Token = Tok_Identifier then
930 Save_Scan_State (Scan_State); -- at Id
931 Scan; -- past Id
933 -- If comma or colon after Id, must be Formal_Part
935 if Token = Tok_Comma or else Token = Tok_Colon then
936 Restore_Scan_State (Scan_State); -- to Id
937 Set_Parameter_Specifications (Decl_Node, P_Formal_Part);
939 -- Else if Id without comma or colon, must be discrete subtype
940 -- defn
942 else
943 Restore_Scan_State (Scan_State); -- to Id
944 Set_Discrete_Subtype_Definition
945 (Decl_Node, P_Discrete_Subtype_Definition);
946 T_Right_Paren;
947 Set_Parameter_Specifications (Decl_Node, P_Parameter_Profile);
948 end if;
950 -- If no Id, must be discrete subtype definition
952 else
953 Set_Discrete_Subtype_Definition
954 (Decl_Node, P_Discrete_Subtype_Definition);
955 T_Right_Paren;
956 Set_Parameter_Specifications (Decl_Node, P_Parameter_Profile);
957 end if;
958 end if;
960 if Is_Overriding then
961 Set_Must_Override (Decl_Node);
962 elsif Not_Overriding then
963 Set_Must_Not_Override (Decl_Node);
964 end if;
966 -- Error recovery check for illegal return
968 if Token = Tok_Return then
969 Error_Msg_SC ("entry cannot have return value!");
970 Scan;
971 Discard_Junk_Node (P_Subtype_Indication);
972 end if;
974 -- Error recovery check for improper use of entry barrier in spec
976 if Token = Tok_When then
977 Error_Msg_SC ("barrier not allowed here (belongs in body)");
978 Scan; -- past WHEN;
979 Discard_Junk_Node (P_Expression_No_Right_Paren);
980 end if;
982 P_Aspect_Specifications (Decl_Node);
983 return Decl_Node;
985 exception
986 when Error_Resync =>
987 Resync_Past_Semicolon;
988 return Error;
989 end P_Entry_Declaration;
991 -----------------------------
992 -- 9.5.2 Accept Statement --
993 -----------------------------
995 -- ACCEPT_STATEMENT ::=
996 -- accept entry_DIRECT_NAME
997 -- [(ENTRY_INDEX)] PARAMETER_PROFILE [do
998 -- HANDLED_SEQUENCE_OF_STATEMENTS
999 -- end [entry_IDENTIFIER]];
1001 -- The caller has checked that the initial token is ACCEPT
1003 -- Error recovery: cannot raise Error_Resync. If an error occurs, the
1004 -- scan is resynchronized past the next semicolon and control returns.
1006 function P_Accept_Statement return Node_Id is
1007 Scan_State : Saved_Scan_State;
1008 Accept_Node : Node_Id;
1009 Hand_Seq : Node_Id;
1011 begin
1012 Push_Scope_Stack;
1013 Scope.Table (Scope.Last).Sloc := Token_Ptr;
1014 Scope.Table (Scope.Last).Ecol := Start_Column;
1016 Accept_Node := New_Node (N_Accept_Statement, Token_Ptr);
1017 Scan; -- past ACCEPT
1018 Scope.Table (Scope.Last).Labl := Token_Node;
1020 Set_Entry_Direct_Name (Accept_Node, P_Identifier (C_Do));
1022 -- Left paren could be (Entry_Index) or Formal_Part, determine which
1024 if Token = Tok_Left_Paren then
1025 Save_Scan_State (Scan_State); -- at left paren
1026 Scan; -- past left paren
1028 -- If first token after left paren not identifier, then Entry_Index
1030 if Token /= Tok_Identifier then
1031 Set_Entry_Index (Accept_Node, P_Expression);
1032 T_Right_Paren;
1033 Set_Parameter_Specifications (Accept_Node, P_Parameter_Profile);
1035 -- First token after left paren is identifier, could be either case
1037 else -- Token = Tok_Identifier
1038 Scan; -- past identifier
1040 -- If identifier followed by comma or colon, must be Formal_Part
1042 if Token = Tok_Comma or else Token = Tok_Colon then
1043 Restore_Scan_State (Scan_State); -- to left paren
1044 Set_Parameter_Specifications (Accept_Node, P_Parameter_Profile);
1046 -- If identifier not followed by comma/colon, must be entry index
1048 else
1049 Restore_Scan_State (Scan_State); -- to left paren
1050 Scan; -- past left paren (again)
1051 Set_Entry_Index (Accept_Node, P_Expression);
1052 T_Right_Paren;
1053 Set_Parameter_Specifications (Accept_Node, P_Parameter_Profile);
1054 end if;
1055 end if;
1056 end if;
1058 -- Scan out DO if present
1060 if Token = Tok_Do then
1061 Scope.Table (Scope.Last).Etyp := E_Name;
1062 Scope.Table (Scope.Last).Lreq := False;
1063 Scan; -- past DO
1064 Hand_Seq := P_Handled_Sequence_Of_Statements;
1065 Set_Handled_Statement_Sequence (Accept_Node, Hand_Seq);
1066 End_Statements (Handled_Statement_Sequence (Accept_Node));
1068 -- Exception handlers not allowed in Ada 95 node
1070 if Present (Exception_Handlers (Hand_Seq)) then
1071 if Ada_Version = Ada_83 then
1072 Error_Msg_N
1073 ("(Ada 83) exception handlers in accept not allowed",
1074 First_Non_Pragma (Exception_Handlers (Hand_Seq)));
1075 end if;
1076 end if;
1078 else
1079 Pop_Scope_Stack; -- discard unused entry
1080 TF_Semicolon;
1081 end if;
1083 return Accept_Node;
1085 -- If error, resynchronize past semicolon
1087 exception
1088 when Error_Resync =>
1089 Resync_Past_Semicolon;
1090 Pop_Scope_Stack; -- discard unused entry
1091 return Error;
1093 end P_Accept_Statement;
1095 ------------------------
1096 -- 9.5.2 Entry Index --
1097 ------------------------
1099 -- Parsed by P_Expression (4.4)
1101 -----------------------
1102 -- 9.5.2 Entry Body --
1103 -----------------------
1105 -- ENTRY_BODY ::=
1106 -- entry DEFINING_IDENTIFIER ENTRY_BODY_FORMAL_PART ENTRY_BARRIER is
1107 -- DECLARATIVE_PART
1108 -- begin
1109 -- HANDLED_SEQUENCE_OF_STATEMENTS
1110 -- end [entry_IDENTIFIER];
1112 -- The caller has checked that the initial token is ENTRY
1114 -- Error_Recovery: cannot raise Error_Resync
1116 function P_Entry_Body return Node_Id is
1117 Entry_Node : Node_Id;
1118 Formal_Part_Node : Node_Id;
1119 Name_Node : Node_Id;
1121 begin
1122 Push_Scope_Stack;
1123 Entry_Node := New_Node (N_Entry_Body, Token_Ptr);
1124 Scan; -- past ENTRY
1126 Scope.Table (Scope.Last).Ecol := Start_Column;
1127 Scope.Table (Scope.Last).Lreq := False;
1128 Scope.Table (Scope.Last).Etyp := E_Name;
1129 Scope.Table (Scope.Last).Sloc := Token_Ptr;
1131 Name_Node := P_Defining_Identifier;
1132 Set_Defining_Identifier (Entry_Node, Name_Node);
1133 Scope.Table (Scope.Last).Labl := Name_Node;
1135 Formal_Part_Node := P_Entry_Body_Formal_Part;
1136 Set_Entry_Body_Formal_Part (Entry_Node, Formal_Part_Node);
1138 Set_Condition (Formal_Part_Node, P_Entry_Barrier);
1139 Parse_Decls_Begin_End (Entry_Node);
1140 return Entry_Node;
1141 end P_Entry_Body;
1143 -----------------------------------
1144 -- 9.5.2 Entry Body Formal Part --
1145 -----------------------------------
1147 -- ENTRY_BODY_FORMAL_PART ::=
1148 -- [(ENTRY_INDEX_SPECIFICATION)] [PARAMETER_PART]
1150 -- Error_Recovery: cannot raise Error_Resync
1152 function P_Entry_Body_Formal_Part return Node_Id is
1153 Fpart_Node : Node_Id;
1154 Scan_State : Saved_Scan_State;
1156 begin
1157 Fpart_Node := New_Node (N_Entry_Body_Formal_Part, Token_Ptr);
1159 -- See if entry index specification present, and if so parse it
1161 if Token = Tok_Left_Paren then
1162 Save_Scan_State (Scan_State); -- at left paren
1163 Scan; -- past left paren
1165 if Token = Tok_For then
1166 Set_Entry_Index_Specification
1167 (Fpart_Node, P_Entry_Index_Specification);
1168 T_Right_Paren;
1169 else
1170 Restore_Scan_State (Scan_State); -- to left paren
1171 end if;
1173 -- Check for (common?) case of left paren omitted before FOR. This
1174 -- is a tricky case, because the corresponding missing left paren
1175 -- can cause real havoc if a formal part is present which gets
1176 -- treated as part of the discrete subtype definition of the
1177 -- entry index specification, so just give error and resynchronize
1179 elsif Token = Tok_For then
1180 T_Left_Paren; -- to give error message
1181 Resync_To_When;
1182 end if;
1184 Set_Parameter_Specifications (Fpart_Node, P_Parameter_Profile);
1185 return Fpart_Node;
1186 end P_Entry_Body_Formal_Part;
1188 --------------------------
1189 -- 9.5.2 Entry Barrier --
1190 --------------------------
1192 -- ENTRY_BARRIER ::= when CONDITION
1194 -- Error_Recovery: cannot raise Error_Resync
1196 function P_Entry_Barrier return Node_Id is
1197 Bnode : Node_Id;
1199 begin
1200 if Token = Tok_When then
1201 Scan; -- past WHEN;
1202 Bnode := P_Expression_No_Right_Paren;
1204 if Token = Tok_Colon_Equal then
1205 Error_Msg_SC -- CODEFIX
1206 ("|"":="" should be ""=""");
1207 Scan;
1208 Bnode := P_Expression_No_Right_Paren;
1209 end if;
1211 else
1212 T_When; -- to give error message
1213 Bnode := Error;
1214 end if;
1216 TF_Is;
1217 return Bnode;
1218 end P_Entry_Barrier;
1220 --------------------------------------
1221 -- 9.5.2 Entry Index Specification --
1222 --------------------------------------
1224 -- ENTRY_INDEX_SPECIFICATION ::=
1225 -- for DEFINING_IDENTIFIER in DISCRETE_SUBTYPE_DEFINITION
1227 -- Error recovery: can raise Error_Resync
1229 function P_Entry_Index_Specification return Node_Id is
1230 Iterator_Node : Node_Id;
1232 begin
1233 Iterator_Node := New_Node (N_Entry_Index_Specification, Token_Ptr);
1234 T_For; -- past FOR
1235 Set_Defining_Identifier (Iterator_Node, P_Defining_Identifier (C_In));
1236 T_In;
1237 Set_Discrete_Subtype_Definition
1238 (Iterator_Node, P_Discrete_Subtype_Definition);
1239 return Iterator_Node;
1240 end P_Entry_Index_Specification;
1242 ---------------------------------
1243 -- 9.5.3 Entry Call Statement --
1244 ---------------------------------
1246 -- Parsed by P_Name (4.1). Within a select, an entry call is parsed
1247 -- by P_Select_Statement (9.7)
1249 ------------------------------
1250 -- 9.5.4 Requeue Statement --
1251 ------------------------------
1253 -- REQUEUE_STATEMENT ::= requeue entry_NAME [with abort];
1255 -- The caller has checked that the initial token is requeue
1257 -- Error recovery: can raise Error_Resync
1259 function P_Requeue_Statement return Node_Id is
1260 Requeue_Node : Node_Id;
1262 begin
1263 Requeue_Node := New_Node (N_Requeue_Statement, Token_Ptr);
1264 Scan; -- past REQUEUE
1265 Set_Name (Requeue_Node, P_Name);
1267 if Token = Tok_With then
1268 Scan; -- past WITH
1269 T_Abort;
1270 Set_Abort_Present (Requeue_Node, True);
1271 end if;
1273 TF_Semicolon;
1274 return Requeue_Node;
1275 end P_Requeue_Statement;
1277 --------------------------
1278 -- 9.6 Delay Statement --
1279 --------------------------
1281 -- DELAY_STATEMENT ::=
1282 -- DELAY_UNTIL_STATEMENT
1283 -- | DELAY_RELATIVE_STATEMENT
1285 -- The caller has checked that the initial token is DELAY
1287 -- Error recovery: cannot raise Error_Resync
1289 function P_Delay_Statement return Node_Id is
1290 begin
1291 Scan; -- past DELAY
1293 -- The following check for delay until misused in Ada 83 doesn't catch
1294 -- all cases, but it's good enough to catch most of them.
1296 if Token_Name = Name_Until then
1297 Check_95_Keyword (Tok_Until, Tok_Left_Paren);
1298 Check_95_Keyword (Tok_Until, Tok_Identifier);
1299 end if;
1301 if Token = Tok_Until then
1302 return P_Delay_Until_Statement;
1303 else
1304 return P_Delay_Relative_Statement;
1305 end if;
1306 end P_Delay_Statement;
1308 --------------------------------
1309 -- 9.6 Delay Until Statement --
1310 --------------------------------
1312 -- DELAY_UNTIL_STATEMENT ::= delay until delay_EXPRESSION;
1314 -- The caller has checked that the initial token is DELAY, scanned it
1315 -- out and checked that the current token is UNTIL
1317 -- Error recovery: cannot raise Error_Resync
1319 function P_Delay_Until_Statement return Node_Id is
1320 Delay_Node : Node_Id;
1322 begin
1323 Delay_Node := New_Node (N_Delay_Until_Statement, Prev_Token_Ptr);
1324 Scan; -- past UNTIL
1325 Set_Expression (Delay_Node, P_Expression_No_Right_Paren);
1326 TF_Semicolon;
1327 return Delay_Node;
1328 end P_Delay_Until_Statement;
1330 -----------------------------------
1331 -- 9.6 Delay Relative Statement --
1332 -----------------------------------
1334 -- DELAY_RELATIVE_STATEMENT ::= delay delay_EXPRESSION;
1336 -- The caller has checked that the initial token is DELAY, scanned it
1337 -- out and determined that the current token is not UNTIL
1339 -- Error recovery: cannot raise Error_Resync
1341 function P_Delay_Relative_Statement return Node_Id is
1342 Delay_Node : Node_Id;
1344 begin
1345 Delay_Node := New_Node (N_Delay_Relative_Statement, Prev_Token_Ptr);
1346 Set_Expression (Delay_Node, P_Expression_No_Right_Paren);
1347 Check_Simple_Expression_In_Ada_83 (Expression (Delay_Node));
1348 TF_Semicolon;
1349 return Delay_Node;
1350 end P_Delay_Relative_Statement;
1352 ---------------------------
1353 -- 9.7 Select Statement --
1354 ---------------------------
1356 -- SELECT_STATEMENT ::=
1357 -- SELECTIVE_ACCEPT
1358 -- | TIMED_ENTRY_CALL
1359 -- | CONDITIONAL_ENTRY_CALL
1360 -- | ASYNCHRONOUS_SELECT
1362 -- SELECTIVE_ACCEPT ::=
1363 -- select
1364 -- [GUARD]
1365 -- SELECT_ALTERNATIVE
1366 -- {or
1367 -- [GUARD]
1368 -- SELECT_ALTERNATIVE
1369 -- [else
1370 -- SEQUENCE_OF_STATEMENTS]
1371 -- end select;
1373 -- GUARD ::= when CONDITION =>
1375 -- Note: the guard preceding a select alternative is included as part
1376 -- of the node generated for a selective accept alternative.
1378 -- SELECT_ALTERNATIVE ::=
1379 -- ACCEPT_ALTERNATIVE
1380 -- | DELAY_ALTERNATIVE
1381 -- | TERMINATE_ALTERNATIVE
1383 -- TIMED_ENTRY_CALL ::=
1384 -- select
1385 -- ENTRY_CALL_ALTERNATIVE
1386 -- or
1387 -- DELAY_ALTERNATIVE
1388 -- end select;
1390 -- CONDITIONAL_ENTRY_CALL ::=
1391 -- select
1392 -- ENTRY_CALL_ALTERNATIVE
1393 -- else
1394 -- SEQUENCE_OF_STATEMENTS
1395 -- end select;
1397 -- ENTRY_CALL_ALTERNATIVE ::=
1398 -- ENTRY_CALL_STATEMENT [SEQUENCE_OF_STATEMENTS]
1400 -- ASYNCHRONOUS_SELECT ::=
1401 -- select
1402 -- TRIGGERING_ALTERNATIVE
1403 -- then abort
1404 -- ABORTABLE_PART
1405 -- end select;
1407 -- TRIGGERING_ALTERNATIVE ::=
1408 -- TRIGGERING_STATEMENT [SEQUENCE_OF_STATEMENTS]
1410 -- TRIGGERING_STATEMENT ::= ENTRY_CALL_STATEMENT | DELAY_STATEMENT
1412 -- The caller has checked that the initial token is SELECT
1414 -- Error recovery: can raise Error_Resync
1416 function P_Select_Statement return Node_Id is
1417 Select_Node : Node_Id;
1418 Select_Sloc : Source_Ptr;
1419 Stmnt_Sloc : Source_Ptr;
1420 Ecall_Node : Node_Id;
1421 Alternative : Node_Id;
1422 Select_Pragmas : List_Id;
1423 Alt_Pragmas : List_Id;
1424 Statement_List : List_Id;
1425 Alt_List : List_Id;
1426 Cond_Expr : Node_Id;
1427 Delay_Stmnt : Node_Id;
1429 begin
1430 Push_Scope_Stack;
1431 Scope.Table (Scope.Last).Etyp := E_Select;
1432 Scope.Table (Scope.Last).Ecol := Start_Column;
1433 Scope.Table (Scope.Last).Sloc := Token_Ptr;
1434 Scope.Table (Scope.Last).Labl := Error;
1436 Select_Sloc := Token_Ptr;
1437 Scan; -- past SELECT
1438 Stmnt_Sloc := Token_Ptr;
1439 Select_Pragmas := P_Pragmas_Opt;
1441 -- If first token after select is designator, then we have an entry
1442 -- call, which must be the start of a conditional entry call, timed
1443 -- entry call or asynchronous select
1445 if Token in Token_Class_Desig then
1447 -- Scan entry call statement
1449 begin
1450 Ecall_Node := P_Name;
1452 -- ?? The following two clauses exactly parallel code in ch5
1453 -- and should be combined sometime
1455 if Nkind (Ecall_Node) = N_Indexed_Component then
1456 declare
1457 Prefix_Node : constant Node_Id := Prefix (Ecall_Node);
1458 Exprs_Node : constant List_Id := Expressions (Ecall_Node);
1460 begin
1461 Change_Node (Ecall_Node, N_Procedure_Call_Statement);
1462 Set_Name (Ecall_Node, Prefix_Node);
1463 Set_Parameter_Associations (Ecall_Node, Exprs_Node);
1464 end;
1466 elsif Nkind (Ecall_Node) = N_Function_Call then
1467 declare
1468 Fname_Node : constant Node_Id := Name (Ecall_Node);
1469 Params_List : constant List_Id :=
1470 Parameter_Associations (Ecall_Node);
1472 begin
1473 Change_Node (Ecall_Node, N_Procedure_Call_Statement);
1474 Set_Name (Ecall_Node, Fname_Node);
1475 Set_Parameter_Associations (Ecall_Node, Params_List);
1476 end;
1478 elsif Nkind (Ecall_Node) = N_Identifier
1479 or else Nkind (Ecall_Node) = N_Selected_Component
1480 then
1481 -- Case of a call to a parameterless entry
1483 declare
1484 C_Node : constant Node_Id :=
1485 New_Node (N_Procedure_Call_Statement, Stmnt_Sloc);
1486 begin
1487 Set_Name (C_Node, Ecall_Node);
1488 Set_Parameter_Associations (C_Node, No_List);
1489 Ecall_Node := C_Node;
1490 end;
1491 end if;
1493 TF_Semicolon;
1495 exception
1496 when Error_Resync =>
1497 Resync_Past_Semicolon;
1498 return Error;
1499 end;
1501 Statement_List := P_Sequence_Of_Statements (SS_Eltm_Ortm_Tatm);
1503 -- OR follows, we have a timed entry call
1505 if Token = Tok_Or then
1506 Scan; -- past OR
1507 Alt_Pragmas := P_Pragmas_Opt;
1509 Select_Node := New_Node (N_Timed_Entry_Call, Select_Sloc);
1510 Set_Entry_Call_Alternative (Select_Node,
1511 Make_Entry_Call_Alternative (Stmnt_Sloc,
1512 Entry_Call_Statement => Ecall_Node,
1513 Pragmas_Before => Select_Pragmas,
1514 Statements => Statement_List));
1516 -- Only possibility is delay alternative. If we have anything
1517 -- else, give message, and treat as conditional entry call.
1519 if Token /= Tok_Delay then
1520 Error_Msg_SC
1521 ("only allowed alternative in timed entry call is delay!");
1522 Discard_Junk_List (P_Sequence_Of_Statements (SS_Sreq));
1523 Set_Delay_Alternative (Select_Node, Error);
1525 else
1526 Set_Delay_Alternative (Select_Node, P_Delay_Alternative);
1527 Set_Pragmas_Before
1528 (Delay_Alternative (Select_Node), Alt_Pragmas);
1529 end if;
1531 -- ELSE follows, we have a conditional entry call
1533 elsif Token = Tok_Else then
1534 Scan; -- past ELSE
1535 Select_Node := New_Node (N_Conditional_Entry_Call, Select_Sloc);
1537 Set_Entry_Call_Alternative (Select_Node,
1538 Make_Entry_Call_Alternative (Stmnt_Sloc,
1539 Entry_Call_Statement => Ecall_Node,
1540 Pragmas_Before => Select_Pragmas,
1541 Statements => Statement_List));
1543 Set_Else_Statements
1544 (Select_Node, P_Sequence_Of_Statements (SS_Sreq));
1546 -- Only remaining case is THEN ABORT (asynchronous select)
1548 elsif Token = Tok_Abort then
1549 Select_Node :=
1550 Make_Asynchronous_Select (Select_Sloc,
1551 Triggering_Alternative =>
1552 Make_Triggering_Alternative (Stmnt_Sloc,
1553 Triggering_Statement => Ecall_Node,
1554 Pragmas_Before => Select_Pragmas,
1555 Statements => Statement_List),
1556 Abortable_Part => P_Abortable_Part);
1558 -- Else error
1560 else
1561 if Ada_Version = Ada_83 then
1562 Error_Msg_BC ("OR or ELSE expected");
1563 else
1564 Error_Msg_BC ("OR or ELSE or THEN ABORT expected");
1565 end if;
1567 Select_Node := Error;
1568 end if;
1570 End_Statements;
1572 -- Here we have a selective accept or an asynchronous select (first
1573 -- token after SELECT is other than a designator token).
1575 else
1576 -- If we have delay with no guard, could be asynchronous select
1578 if Token = Tok_Delay then
1579 Delay_Stmnt := P_Delay_Statement;
1580 Statement_List := P_Sequence_Of_Statements (SS_Eltm_Ortm_Tatm);
1582 -- Asynchronous select
1584 if Token = Tok_Abort then
1585 Select_Node :=
1586 Make_Asynchronous_Select (Select_Sloc,
1587 Triggering_Alternative =>
1588 Make_Triggering_Alternative (Stmnt_Sloc,
1589 Triggering_Statement => Delay_Stmnt,
1590 Pragmas_Before => Select_Pragmas,
1591 Statements => Statement_List),
1592 Abortable_Part => P_Abortable_Part);
1594 End_Statements;
1595 return Select_Node;
1597 -- Delay which was not an asynchronous select. Must be a selective
1598 -- accept, and since at least one accept statement is required,
1599 -- we must have at least one OR phrase present.
1601 else
1602 Alt_List := New_List (
1603 Make_Delay_Alternative (Stmnt_Sloc,
1604 Delay_Statement => Delay_Stmnt,
1605 Pragmas_Before => Select_Pragmas,
1606 Statements => Statement_List));
1607 T_Or;
1608 Alt_Pragmas := P_Pragmas_Opt;
1609 end if;
1611 -- If not a delay statement, then must be another possibility for
1612 -- a selective accept alternative, or perhaps a guard is present
1614 else
1615 Alt_List := New_List;
1616 Alt_Pragmas := Select_Pragmas;
1617 end if;
1619 Select_Node := New_Node (N_Selective_Accept, Select_Sloc);
1620 Set_Select_Alternatives (Select_Node, Alt_List);
1622 -- Scan out selective accept alternatives. On entry to this loop,
1623 -- we are just past a SELECT or OR token, and any pragmas that
1624 -- immediately follow the SELECT or OR are in Alt_Pragmas.
1626 loop
1627 if Token = Tok_When then
1629 if Present (Alt_Pragmas) then
1630 Error_Msg_SC ("pragmas may not precede guard");
1631 end if;
1633 Scan; -- past WHEN
1634 Cond_Expr := P_Expression_No_Right_Paren;
1635 T_Arrow;
1636 Alt_Pragmas := P_Pragmas_Opt;
1638 else
1639 Cond_Expr := Empty;
1640 end if;
1642 if Token = Tok_Accept then
1643 Alternative := P_Accept_Alternative;
1645 -- Check for junk attempt at asynchronous select using
1646 -- an Accept alternative as the triggering statement
1648 if Token = Tok_Abort
1649 and then Is_Empty_List (Alt_List)
1650 and then No (Cond_Expr)
1651 then
1652 Error_Msg
1653 ("triggering statement must be entry call or delay",
1654 Sloc (Alternative));
1655 Scan; -- past junk ABORT
1656 Discard_Junk_List (P_Sequence_Of_Statements (SS_Sreq));
1657 End_Statements;
1658 return Error;
1659 end if;
1661 elsif Token = Tok_Delay then
1662 Alternative := P_Delay_Alternative;
1664 elsif Token = Tok_Terminate then
1665 Alternative := P_Terminate_Alternative;
1667 else
1668 Error_Msg_SC
1669 ("select alternative (ACCEPT, ABORT, DELAY) expected");
1670 Alternative := Error;
1672 if Token = Tok_Semicolon then
1673 Scan; -- past junk semicolon
1674 end if;
1675 end if;
1677 -- THEN ABORT at this stage is just junk
1679 if Token = Tok_Abort then
1680 Error_Msg_SP ("misplaced `THEN ABORT`");
1681 Scan; -- past junk ABORT
1682 Discard_Junk_List (P_Sequence_Of_Statements (SS_Sreq));
1683 End_Statements;
1684 return Error;
1686 else
1687 if Alternative /= Error then
1688 Set_Condition (Alternative, Cond_Expr);
1689 Set_Pragmas_Before (Alternative, Alt_Pragmas);
1690 Append (Alternative, Alt_List);
1691 end if;
1693 exit when Token /= Tok_Or;
1694 end if;
1696 T_Or;
1697 Alt_Pragmas := P_Pragmas_Opt;
1698 end loop;
1700 if Token = Tok_Else then
1701 Scan; -- past ELSE
1702 Set_Else_Statements
1703 (Select_Node, P_Sequence_Of_Statements (SS_Ortm_Sreq));
1705 if Token = Tok_Or then
1706 Error_Msg_SC ("select alternative cannot follow else part!");
1707 end if;
1708 end if;
1710 End_Statements;
1711 end if;
1713 return Select_Node;
1714 end P_Select_Statement;
1716 -----------------------------
1717 -- 9.7.1 Selective Accept --
1718 -----------------------------
1720 -- Parsed by P_Select_Statement (9.7)
1722 ------------------
1723 -- 9.7.1 Guard --
1724 ------------------
1726 -- Parsed by P_Select_Statement (9.7)
1728 -------------------------------
1729 -- 9.7.1 Select Alternative --
1730 -------------------------------
1732 -- SELECT_ALTERNATIVE ::=
1733 -- ACCEPT_ALTERNATIVE
1734 -- | DELAY_ALTERNATIVE
1735 -- | TERMINATE_ALTERNATIVE
1737 -- Note: the guard preceding a select alternative is included as part
1738 -- of the node generated for a selective accept alternative.
1740 -- Error recovery: cannot raise Error_Resync
1742 -------------------------------
1743 -- 9.7.1 Accept Alternative --
1744 -------------------------------
1746 -- ACCEPT_ALTERNATIVE ::=
1747 -- ACCEPT_STATEMENT [SEQUENCE_OF_STATEMENTS]
1749 -- Error_Recovery: Cannot raise Error_Resync
1751 -- Note: the caller is responsible for setting the Pragmas_Before
1752 -- field of the returned N_Terminate_Alternative node.
1754 function P_Accept_Alternative return Node_Id is
1755 Accept_Alt_Node : Node_Id;
1757 begin
1758 Accept_Alt_Node := New_Node (N_Accept_Alternative, Token_Ptr);
1759 Set_Accept_Statement (Accept_Alt_Node, P_Accept_Statement);
1761 -- Note: the reason that we accept THEN ABORT as a terminator for
1762 -- the sequence of statements is for error recovery which allows
1763 -- for misuse of an accept statement as a triggering statement.
1765 Set_Statements
1766 (Accept_Alt_Node, P_Sequence_Of_Statements (SS_Eltm_Ortm_Tatm));
1767 return Accept_Alt_Node;
1768 end P_Accept_Alternative;
1770 ------------------------------
1771 -- 9.7.1 Delay Alternative --
1772 ------------------------------
1774 -- DELAY_ALTERNATIVE ::=
1775 -- DELAY_STATEMENT [SEQUENCE_OF_STATEMENTS]
1777 -- Error_Recovery: Cannot raise Error_Resync
1779 -- Note: the caller is responsible for setting the Pragmas_Before
1780 -- field of the returned N_Terminate_Alternative node.
1782 function P_Delay_Alternative return Node_Id is
1783 Delay_Alt_Node : Node_Id;
1785 begin
1786 Delay_Alt_Node := New_Node (N_Delay_Alternative, Token_Ptr);
1787 Set_Delay_Statement (Delay_Alt_Node, P_Delay_Statement);
1789 -- Note: the reason that we accept THEN ABORT as a terminator for
1790 -- the sequence of statements is for error recovery which allows
1791 -- for misuse of an accept statement as a triggering statement.
1793 Set_Statements
1794 (Delay_Alt_Node, P_Sequence_Of_Statements (SS_Eltm_Ortm_Tatm));
1795 return Delay_Alt_Node;
1796 end P_Delay_Alternative;
1798 ----------------------------------
1799 -- 9.7.1 Terminate Alternative --
1800 ----------------------------------
1802 -- TERMINATE_ALTERNATIVE ::= terminate;
1804 -- Error_Recovery: Cannot raise Error_Resync
1806 -- Note: the caller is responsible for setting the Pragmas_Before
1807 -- field of the returned N_Terminate_Alternative node.
1809 function P_Terminate_Alternative return Node_Id is
1810 Terminate_Alt_Node : Node_Id;
1812 begin
1813 Terminate_Alt_Node := New_Node (N_Terminate_Alternative, Token_Ptr);
1814 Scan; -- past TERMINATE
1815 TF_Semicolon;
1817 -- For all other select alternatives, the sequence of statements
1818 -- after the alternative statement will swallow up any pragmas
1819 -- coming in this position. But the terminate alternative has no
1820 -- sequence of statements, so the pragmas here must be treated
1821 -- specially.
1823 Set_Pragmas_After (Terminate_Alt_Node, P_Pragmas_Opt);
1824 return Terminate_Alt_Node;
1825 end P_Terminate_Alternative;
1827 -----------------------------
1828 -- 9.7.2 Timed Entry Call --
1829 -----------------------------
1831 -- Parsed by P_Select_Statement (9.7)
1833 -----------------------------------
1834 -- 9.7.2 Entry Call Alternative --
1835 -----------------------------------
1837 -- Parsed by P_Select_Statement (9.7)
1839 -----------------------------------
1840 -- 9.7.3 Conditional Entry Call --
1841 -----------------------------------
1843 -- Parsed by P_Select_Statement (9.7)
1845 --------------------------------
1846 -- 9.7.4 Asynchronous Select --
1847 --------------------------------
1849 -- Parsed by P_Select_Statement (9.7)
1851 -----------------------------------
1852 -- 9.7.4 Triggering Alternative --
1853 -----------------------------------
1855 -- Parsed by P_Select_Statement (9.7)
1857 ---------------------------------
1858 -- 9.7.4 Triggering Statement --
1859 ---------------------------------
1861 -- Parsed by P_Select_Statement (9.7)
1863 ---------------------------
1864 -- 9.7.4 Abortable Part --
1865 ---------------------------
1867 -- ABORTABLE_PART ::= SEQUENCE_OF_STATEMENTS
1869 -- The caller has verified that THEN ABORT is present, and Token is
1870 -- pointing to the ABORT on entry (or if not, then we have an error)
1872 -- Error recovery: cannot raise Error_Resync
1874 function P_Abortable_Part return Node_Id is
1875 Abortable_Part_Node : Node_Id;
1877 begin
1878 Abortable_Part_Node := New_Node (N_Abortable_Part, Token_Ptr);
1879 T_Abort; -- scan past ABORT
1881 if Ada_Version = Ada_83 then
1882 Error_Msg_SP ("(Ada 83) asynchronous select not allowed!");
1883 end if;
1885 Set_Statements (Abortable_Part_Node, P_Sequence_Of_Statements (SS_Sreq));
1886 return Abortable_Part_Node;
1887 end P_Abortable_Part;
1889 --------------------------
1890 -- 9.8 Abort Statement --
1891 --------------------------
1893 -- ABORT_STATEMENT ::= abort task_NAME {, task_NAME};
1895 -- The caller has checked that the initial token is ABORT
1897 -- Error recovery: cannot raise Error_Resync
1899 function P_Abort_Statement return Node_Id is
1900 Abort_Node : Node_Id;
1902 begin
1903 Abort_Node := New_Node (N_Abort_Statement, Token_Ptr);
1904 Scan; -- past ABORT
1905 Set_Names (Abort_Node, New_List);
1907 loop
1908 Append (P_Name, Names (Abort_Node));
1909 exit when Token /= Tok_Comma;
1910 Scan; -- past comma
1911 end loop;
1913 TF_Semicolon;
1914 return Abort_Node;
1915 end P_Abort_Statement;
1917 end Ch9;