1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2010, Free Software Foundation, Inc. --
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. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
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.
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_Definition
return Node_Id
;
47 function P_Task_Items
return List_Id
;
49 -----------------------------
50 -- 9.1 Task (also 10.1.3) --
51 -----------------------------
53 -- TASK_TYPE_DECLARATION ::=
54 -- task type DEFINING_IDENTIFIER [KNOWN_DISCRIMINANT_PART]
55 -- [is [new INTERFACE_LIST with] TASK_DEFINITION];
57 -- SINGLE_TASK_DECLARATION ::=
58 -- task DEFINING_IDENTIFIER
59 -- [is [new INTERFACE_LIST with] TASK_DEFINITION];
62 -- task body DEFINING_IDENTIFIER is
65 -- HANDLED_SEQUENCE_OF_STATEMENTS
66 -- end [task_IDENTIFIER]
69 -- task body DEFINING_IDENTIFIER is separate;
71 -- This routine scans out a task declaration, task body, or task stub
73 -- The caller has checked that the initial token is TASK and scanned
74 -- past it, so that Token is set to the token after TASK
76 -- Error recovery: cannot raise Error_Resync
78 function P_Task
return Node_Id
is
81 Task_Sloc
: Source_Ptr
;
85 Scope
.Table
(Scope
.Last
).Etyp
:= E_Name
;
86 Scope
.Table
(Scope
.Last
).Ecol
:= Start_Column
;
87 Scope
.Table
(Scope
.Last
).Sloc
:= Token_Ptr
;
88 Scope
.Table
(Scope
.Last
).Lreq
:= False;
89 Task_Sloc
:= Prev_Token_Ptr
;
91 if Token
= Tok_Body
then
93 Name_Node
:= P_Defining_Identifier
(C_Is
);
94 Scope
.Table
(Scope
.Last
).Labl
:= Name_Node
;
96 if Token
= Tok_Left_Paren
then
97 Error_Msg_SC
("discriminant part not allowed in task body");
98 Discard_Junk_List
(P_Known_Discriminant_Part_Opt
);
105 if Token
= Tok_Separate
then
106 Scan
; -- past SEPARATE
107 Task_Node
:= New_Node
(N_Task_Body_Stub
, Task_Sloc
);
108 Set_Defining_Identifier
(Task_Node
, Name_Node
);
110 Pop_Scope_Stack
; -- remove unused entry
115 Task_Node
:= New_Node
(N_Task_Body
, Task_Sloc
);
116 Set_Defining_Identifier
(Task_Node
, Name_Node
);
117 Parse_Decls_Begin_End
(Task_Node
);
122 -- Otherwise we must have a task declaration
125 if Token
= Tok_Type
then
127 Task_Node
:= New_Node
(N_Task_Type_Declaration
, Task_Sloc
);
128 Name_Node
:= P_Defining_Identifier
;
129 Set_Defining_Identifier
(Task_Node
, Name_Node
);
130 Scope
.Table
(Scope
.Last
).Labl
:= Name_Node
;
131 Set_Discriminant_Specifications
132 (Task_Node
, P_Known_Discriminant_Part_Opt
);
135 Task_Node
:= New_Node
(N_Single_Task_Declaration
, Task_Sloc
);
136 Name_Node
:= P_Defining_Identifier
(C_Is
);
137 Set_Defining_Identifier
(Task_Node
, Name_Node
);
138 Scope
.Table
(Scope
.Last
).Labl
:= Name_Node
;
140 if Token
= Tok_Left_Paren
then
141 Error_Msg_SC
("discriminant part not allowed for single task");
142 Discard_Junk_List
(P_Known_Discriminant_Part_Opt
);
146 -- Parse optional task definition. Note that P_Task_Definition scans
147 -- out the semicolon as well as the task definition itself.
149 if Token
= Tok_Semicolon
then
151 -- A little check, if the next token after semicolon is
152 -- Entry, then surely the semicolon should really be IS
154 Scan
; -- past semicolon
156 if Token
= Tok_Entry
then
157 Error_Msg_SP
-- CODEFIX
158 ("|"";"" should be IS");
159 Set_Task_Definition
(Task_Node
, P_Task_Definition
);
161 Pop_Scope_Stack
; -- Remove unused entry
164 TF_Is
; -- must have IS if no semicolon
168 if Token
= Tok_New
then
171 if Ada_Version
< Ada_05
then
172 Error_Msg_SP
("task interface is an Ada 2005 extension");
173 Error_Msg_SP
("\unit must be compiled with -gnat05 switch");
176 Set_Interface_List
(Task_Node
, New_List
);
179 Append
(P_Qualified_Simple_Name
, Interface_List
(Task_Node
));
180 exit when Token
/= Tok_And
;
184 if Token
/= Tok_With
then
185 Error_Msg_SC
-- CODEFIX
191 if Token
= Tok_Private
then
192 Error_Msg_SP
-- CODEFIX
193 ("PRIVATE not allowed in task type declaration");
197 Set_Task_Definition
(Task_Node
, P_Task_Definition
);
204 --------------------------------
205 -- 9.1 Task Type Declaration --
206 --------------------------------
208 -- Parsed by P_Task (9.1)
210 ----------------------------------
211 -- 9.1 Single Task Declaration --
212 ----------------------------------
214 -- Parsed by P_Task (9.1)
216 --------------------------
217 -- 9.1 Task Definition --
218 --------------------------
220 -- TASK_DEFINITION ::=
224 -- end [task_IDENTIFIER];
226 -- The caller has already made the scope stack entry
228 -- Note: there is a small deviation from official syntax here in that we
229 -- regard the semicolon after end as part of the Task_Definition, and in
230 -- the official syntax, it's part of the enclosing declaration. The reason
231 -- for this deviation is that otherwise the end processing would have to
232 -- be special cased, which would be a nuisance!
234 -- Error recovery: cannot raise Error_Resync
236 function P_Task_Definition
return Node_Id
is
240 Def_Node
:= New_Node
(N_Task_Definition
, Token_Ptr
);
241 Set_Visible_Declarations
(Def_Node
, P_Task_Items
);
243 if Token
= Tok_Private
then
244 Scan
; -- past PRIVATE
245 Set_Private_Declarations
(Def_Node
, P_Task_Items
);
247 -- Deal gracefully with multiple PRIVATE parts
249 while Token
= Tok_Private
loop
250 Error_Msg_SC
("only one private part allowed per task");
251 Scan
; -- past PRIVATE
252 Append_List
(P_Task_Items
, Private_Declarations
(Def_Node
));
256 End_Statements
(Def_Node
);
258 end P_Task_Definition
;
264 -- TASK_ITEM ::= ENTRY_DECLARATION | REPRESENTATION_CLAUSE
266 -- This subprogram scans a (possibly empty) list of task items and pragmas
268 -- Error recovery: cannot raise Error_Resync
270 -- Note: a pragma can also be returned in this position
272 function P_Task_Items
return List_Id
is
275 Decl_Sloc
: Source_Ptr
;
278 -- Get rid of active SIS entry from outer scope. This means we will
279 -- miss some nested cases, but it doesn't seem worth the effort. See
280 -- discussion in Par for further details
282 SIS_Entry_Active
:= False;
284 -- Loop to scan out task items
289 Decl_Sloc
:= Token_Ptr
;
291 if Token
= Tok_Pragma
then
292 Append
(P_Pragma
, Items
);
294 -- Ada 2005 (AI-397): Reserved words NOT and OVERRIDING
295 -- may begin an entry declaration.
297 elsif Token
= Tok_Entry
298 or else Token
= Tok_Not
299 or else Token
= Tok_Overriding
301 Append
(P_Entry_Declaration
, Items
);
303 elsif Token
= Tok_For
then
304 -- Representation clause in task declaration. The only rep
305 -- clause which is legal in a protected is an address clause,
306 -- so that is what we try to scan out.
308 Item_Node
:= P_Representation_Clause
;
310 if Nkind
(Item_Node
) = N_At_Clause
then
311 Append
(Item_Node
, Items
);
313 elsif Nkind
(Item_Node
) = N_Attribute_Definition_Clause
314 and then Chars
(Item_Node
) = Name_Address
316 Append
(Item_Node
, Items
);
320 ("the only representation clause " &
321 "allowed here is an address clause!", Decl_Sloc
);
324 elsif Token
= Tok_Identifier
325 or else Token
in Token_Class_Declk
327 Error_Msg_SC
("illegal declaration in task definition");
328 Resync_Past_Semicolon
;
342 -- Parsed by P_Task (9.1)
344 ----------------------------------
345 -- 9.4 Protected (also 10.1.3) --
346 ----------------------------------
348 -- PROTECTED_TYPE_DECLARATION ::=
349 -- protected type DEFINING_IDENTIFIER [KNOWN_DISCRIMINANT_PART]
350 -- is [new INTERFACE_LIST with] PROTECTED_DEFINITION;
352 -- SINGLE_PROTECTED_DECLARATION ::=
353 -- protected DEFINING_IDENTIFIER
354 -- is [new INTERFACE_LIST with] PROTECTED_DEFINITION;
356 -- PROTECTED_BODY ::=
357 -- protected body DEFINING_IDENTIFIER is
358 -- {PROTECTED_OPERATION_ITEM}
359 -- end [protected_IDENTIFIER];
361 -- PROTECTED_BODY_STUB ::=
362 -- protected body DEFINING_IDENTIFIER is separate;
364 -- This routine scans out a protected declaration, protected body
365 -- or a protected stub.
367 -- The caller has checked that the initial token is PROTECTED and
368 -- scanned past it, so Token is set to the following token.
370 -- Error recovery: cannot raise Error_Resync
372 function P_Protected
return Node_Id
is
374 Protected_Node
: Node_Id
;
375 Protected_Sloc
: Source_Ptr
;
376 Scan_State
: Saved_Scan_State
;
380 Scope
.Table
(Scope
.Last
).Etyp
:= E_Name
;
381 Scope
.Table
(Scope
.Last
).Ecol
:= Start_Column
;
382 Scope
.Table
(Scope
.Last
).Lreq
:= False;
383 Protected_Sloc
:= Prev_Token_Ptr
;
385 if Token
= Tok_Body
then
387 Name_Node
:= P_Defining_Identifier
(C_Is
);
388 Scope
.Table
(Scope
.Last
).Labl
:= Name_Node
;
390 if Token
= Tok_Left_Paren
then
391 Error_Msg_SC
("discriminant part not allowed in protected body");
392 Discard_Junk_List
(P_Known_Discriminant_Part_Opt
);
399 if Token
= Tok_Separate
then
400 Scan
; -- past SEPARATE
401 Protected_Node
:= New_Node
(N_Protected_Body_Stub
, Protected_Sloc
);
402 Set_Defining_Identifier
(Protected_Node
, Name_Node
);
404 Pop_Scope_Stack
; -- remove unused entry
409 Protected_Node
:= New_Node
(N_Protected_Body
, Protected_Sloc
);
410 Set_Defining_Identifier
(Protected_Node
, Name_Node
);
411 Set_Declarations
(Protected_Node
, P_Protected_Operation_Items
);
412 End_Statements
(Protected_Node
);
415 return Protected_Node
;
417 -- Otherwise we must have a protected declaration
420 if Token
= Tok_Type
then
423 New_Node
(N_Protected_Type_Declaration
, Protected_Sloc
);
424 Name_Node
:= P_Defining_Identifier
(C_Is
);
425 Set_Defining_Identifier
(Protected_Node
, Name_Node
);
426 Scope
.Table
(Scope
.Last
).Labl
:= Name_Node
;
427 Set_Discriminant_Specifications
428 (Protected_Node
, P_Known_Discriminant_Part_Opt
);
432 New_Node
(N_Single_Protected_Declaration
, Protected_Sloc
);
433 Name_Node
:= P_Defining_Identifier
(C_Is
);
434 Set_Defining_Identifier
(Protected_Node
, Name_Node
);
436 if Token
= Tok_Left_Paren
then
438 ("discriminant part not allowed for single protected");
439 Discard_Junk_List
(P_Known_Discriminant_Part_Opt
);
442 Scope
.Table
(Scope
.Last
).Labl
:= Name_Node
;
445 -- Check for semicolon not followed by IS, this is something like
451 -- protected type r IS END;
453 if Token
= Tok_Semicolon
then
454 Save_Scan_State
(Scan_State
); -- at semicolon
455 Scan
; -- past semicolon
457 if Token
/= Tok_Is
then
458 Restore_Scan_State
(Scan_State
);
459 Error_Msg_SC
-- CODEFIX
461 Set_Protected_Definition
(Protected_Node
,
462 Make_Protected_Definition
(Token_Ptr
,
463 Visible_Declarations
=> Empty_List
,
464 End_Label
=> Empty
));
466 SIS_Entry_Active
:= False;
467 End_Statements
(Protected_Definition
(Protected_Node
));
468 Scan
; -- past semicolon
469 return Protected_Node
;
472 Error_Msg_SP
-- CODEFIX
473 ("|extra ""("" ignored");
480 if Token
= Tok_New
then
483 if Ada_Version
< Ada_05
then
484 Error_Msg_SP
("protected interface is an Ada 2005 extension");
485 Error_Msg_SP
("\unit must be compiled with -gnat05 switch");
488 Set_Interface_List
(Protected_Node
, New_List
);
491 Append
(P_Qualified_Simple_Name
,
492 Interface_List
(Protected_Node
));
494 exit when Token
/= Tok_And
;
498 if Token
/= Tok_With
then
499 Error_Msg_SC
-- CODEFIX
506 Set_Protected_Definition
(Protected_Node
, P_Protected_Definition
);
507 return Protected_Node
;
511 -------------------------------------
512 -- 9.4 Protected Type Declaration --
513 -------------------------------------
515 -- Parsed by P_Protected (9.4)
517 ---------------------------------------
518 -- 9.4 Single Protected Declaration --
519 ---------------------------------------
521 -- Parsed by P_Protected (9.4)
523 -------------------------------
524 -- 9.4 Protected Definition --
525 -------------------------------
527 -- PROTECTED_DEFINITION ::=
528 -- {PROTECTED_OPERATION_DECLARATION}
530 -- {PROTECTED_ELEMENT_DECLARATION}]
531 -- end [protected_IDENTIFIER]
533 -- PROTECTED_ELEMENT_DECLARATION ::=
534 -- PROTECTED_OPERATION_DECLARATION
535 -- | COMPONENT_DECLARATION
537 -- The caller has already established the scope stack entry
539 -- Error recovery: cannot raise Error_Resync
541 function P_Protected_Definition
return Node_Id
is
546 Def_Node
:= New_Node
(N_Protected_Definition
, Token_Ptr
);
548 -- Get rid of active SIS entry from outer scope. This means we will
549 -- miss some nested cases, but it doesn't seem worth the effort. See
550 -- discussion in Par for further details
552 SIS_Entry_Active
:= False;
554 -- Loop to scan visible declarations (protected operation declarations)
556 Set_Visible_Declarations
(Def_Node
, New_List
);
559 Item_Node
:= P_Protected_Operation_Declaration_Opt
;
560 exit when No
(Item_Node
);
561 Append
(Item_Node
, Visible_Declarations
(Def_Node
));
564 -- Deal with PRIVATE part (including graceful handling of multiple
567 Private_Loop
: while Token
= Tok_Private
loop
568 if No
(Private_Declarations
(Def_Node
)) then
569 Set_Private_Declarations
(Def_Node
, New_List
);
571 Error_Msg_SC
("duplicate private part");
574 Scan
; -- past PRIVATE
576 Declaration_Loop
: loop
577 if Token
= Tok_Identifier
then
578 P_Component_Items
(Private_Declarations
(Def_Node
));
580 Item_Node
:= P_Protected_Operation_Declaration_Opt
;
581 exit Declaration_Loop
when No
(Item_Node
);
582 Append
(Item_Node
, Private_Declarations
(Def_Node
));
584 end loop Declaration_Loop
;
585 end loop Private_Loop
;
587 End_Statements
(Def_Node
);
589 end P_Protected_Definition
;
591 ------------------------------------------
592 -- 9.4 Protected Operation Declaration --
593 ------------------------------------------
595 -- PROTECTED_OPERATION_DECLARATION ::=
596 -- SUBPROGRAM_DECLARATION
597 -- | ENTRY_DECLARATION
598 -- | REPRESENTATION_CLAUSE
600 -- Error recovery: cannot raise Error_Resync
602 -- Note: a pragma can also be returned in this position
604 -- We are not currently permitting representation clauses to appear as
605 -- protected operation declarations, do we have to rethink this???
607 function P_Protected_Operation_Declaration_Opt
return Node_Id
is
611 function P_Entry_Or_Subprogram_With_Indicator
return Node_Id
;
612 -- Ada 2005 (AI-397): Parse an entry or a subprogram with an overriding
613 -- indicator. The caller has checked that the initial token is NOT or
616 ------------------------------------------
617 -- P_Entry_Or_Subprogram_With_Indicator --
618 ------------------------------------------
620 function P_Entry_Or_Subprogram_With_Indicator
return Node_Id
is
621 Decl
: Node_Id
:= Error
;
622 Is_Overriding
: Boolean := False;
623 Not_Overriding
: Boolean := False;
626 if Token
= Tok_Not
then
629 if Token
= Tok_Overriding
then
630 Scan
; -- past OVERRIDING
631 Not_Overriding
:= True;
633 Error_Msg_SC
-- CODEFIX
634 ("OVERRIDING expected!");
638 Scan
; -- past OVERRIDING
639 Is_Overriding
:= True;
642 if (Is_Overriding
or else Not_Overriding
) then
643 if Ada_Version
< Ada_05
then
644 Error_Msg_SP
("overriding indicator is an Ada 2005 extension");
645 Error_Msg_SP
("\unit must be compiled with -gnat05 switch");
647 elsif Token
= Tok_Entry
then
648 Decl
:= P_Entry_Declaration
;
650 Set_Must_Override
(Decl
, Is_Overriding
);
651 Set_Must_Not_Override
(Decl
, Not_Overriding
);
653 elsif Token
= Tok_Function
or else Token
= Tok_Procedure
then
654 Decl
:= P_Subprogram
(Pf_Decl
);
656 Set_Must_Override
(Specification
(Decl
), Is_Overriding
);
657 Set_Must_Not_Override
(Specification
(Decl
), Not_Overriding
);
660 Error_Msg_SC
-- CODEFIX
661 ("ENTRY, FUNCTION or PROCEDURE expected!");
666 end P_Entry_Or_Subprogram_With_Indicator
;
668 -- Start of processing for P_Protected_Operation_Declaration_Opt
671 -- This loop runs more than once only when a junk declaration
675 if Token
= Tok_Pragma
then
678 elsif Token
= Tok_Not
or else Token
= Tok_Overriding
then
679 return P_Entry_Or_Subprogram_With_Indicator
;
681 elsif Token
= Tok_Entry
then
682 return P_Entry_Declaration
;
684 elsif Token
= Tok_Function
or else Token
= Tok_Procedure
then
685 return P_Subprogram
(Pf_Decl
);
687 elsif Token
= Tok_Identifier
then
690 Skip_Declaration
(L
);
692 if Nkind
(First
(L
)) = N_Object_Declaration
then
694 ("component must be declared in private part of " &
695 "protected type", P
);
698 ("illegal declaration in protected definition", P
);
701 elsif Token
in Token_Class_Declk
then
702 Error_Msg_SC
("illegal declaration in protected definition");
703 Resync_Past_Semicolon
;
705 -- Return now to avoid cascaded messages if next declaration
706 -- is a valid component declaration.
710 elsif Token
= Tok_For
then
712 ("representation clause not allowed in protected definition");
713 Resync_Past_Semicolon
;
719 end P_Protected_Operation_Declaration_Opt
;
721 -----------------------------------
722 -- 9.4 Protected Operation Item --
723 -----------------------------------
725 -- PROTECTED_OPERATION_ITEM ::=
726 -- SUBPROGRAM_DECLARATION
729 -- | REPRESENTATION_CLAUSE
731 -- This procedure parses and returns a list of protected operation items
733 -- We are not currently permitting representation clauses to appear
734 -- as protected operation items, do we have to rethink this???
736 function P_Protected_Operation_Items
return List_Id
is
740 Item_List
:= New_List
;
743 if Token
= Tok_Entry
or else Bad_Spelling_Of
(Tok_Entry
) then
744 Append
(P_Entry_Body
, Item_List
);
746 -- If the operation starts with procedure, function, or an overriding
747 -- indicator ("overriding" or "not overriding"), parse a subprogram.
749 elsif Token
= Tok_Function
or else Bad_Spelling_Of
(Tok_Function
)
751 Token
= Tok_Procedure
or else Bad_Spelling_Of
(Tok_Procedure
)
753 Token
= Tok_Overriding
or else Bad_Spelling_Of
(Tok_Overriding
)
755 Token
= Tok_Not
or else Bad_Spelling_Of
(Tok_Not
)
757 Append
(P_Subprogram
(Pf_Decl_Pbod
), Item_List
);
759 elsif Token
= Tok_Pragma
or else Bad_Spelling_Of
(Tok_Pragma
) then
760 P_Pragmas_Opt
(Item_List
);
762 elsif Token
= Tok_Private
or else Bad_Spelling_Of
(Tok_Private
) then
763 Error_Msg_SC
("PRIVATE not allowed in protected body");
764 Scan
; -- past PRIVATE
766 elsif Token
= Tok_Identifier
then
767 Error_Msg_SC
("all components must be declared in spec!");
768 Resync_Past_Semicolon
;
770 elsif Token
in Token_Class_Declk
then
771 Error_Msg_SC
("this declaration not allowed in protected body");
772 Resync_Past_Semicolon
;
780 end P_Protected_Operation_Items
;
782 ------------------------------
783 -- 9.5.2 Entry Declaration --
784 ------------------------------
786 -- ENTRY_DECLARATION ::=
787 -- [OVERRIDING_INDICATOR]
788 -- entry DEFINING_IDENTIFIER [(DISCRETE_SUBTYPE_DEFINITION)]
789 -- PARAMETER_PROFILE;
791 -- The caller has checked that the initial token is ENTRY, NOT or
794 -- Error recovery: cannot raise Error_Resync
796 function P_Entry_Declaration
return Node_Id
is
798 Scan_State
: Saved_Scan_State
;
800 -- Flags for optional overriding indication. Two flags are needed,
801 -- to distinguish positive and negative overriding indicators from
802 -- the absence of any indicator.
804 Is_Overriding
: Boolean := False;
805 Not_Overriding
: Boolean := False;
808 -- Ada 2005 (AI-397): Scan leading overriding indicator
810 if Token
= Tok_Not
then
813 if Token
= Tok_Overriding
then
814 Scan
; -- part OVERRIDING
815 Not_Overriding
:= True;
817 Error_Msg_SC
-- CODEFIX
818 ("OVERRIDING expected!");
821 elsif Token
= Tok_Overriding
then
822 Scan
; -- part OVERRIDING
823 Is_Overriding
:= True;
826 if (Is_Overriding
or else Not_Overriding
) then
827 if Ada_Version
< Ada_05
then
828 Error_Msg_SP
("overriding indicator is an Ada 2005 extension");
829 Error_Msg_SP
("\unit must be compiled with -gnat05 switch");
831 elsif Token
/= Tok_Entry
then
832 Error_Msg_SC
-- CODEFIX
837 Decl_Node
:= New_Node
(N_Entry_Declaration
, Token_Ptr
);
840 Set_Defining_Identifier
841 (Decl_Node
, P_Defining_Identifier
(C_Left_Paren_Semicolon
));
843 -- If left paren, could be (Discrete_Subtype_Definition) or Formal_Part
845 if Token
= Tok_Left_Paren
then
848 -- If identifier after left paren, could still be either
850 if Token
= Tok_Identifier
then
851 Save_Scan_State
(Scan_State
); -- at Id
854 -- If comma or colon after Id, must be Formal_Part
856 if Token
= Tok_Comma
or else Token
= Tok_Colon
then
857 Restore_Scan_State
(Scan_State
); -- to Id
858 Set_Parameter_Specifications
(Decl_Node
, P_Formal_Part
);
860 -- Else if Id without comma or colon, must be discrete subtype
864 Restore_Scan_State
(Scan_State
); -- to Id
865 Set_Discrete_Subtype_Definition
866 (Decl_Node
, P_Discrete_Subtype_Definition
);
868 Set_Parameter_Specifications
(Decl_Node
, P_Parameter_Profile
);
871 -- If no Id, must be discrete subtype definition
874 Set_Discrete_Subtype_Definition
875 (Decl_Node
, P_Discrete_Subtype_Definition
);
877 Set_Parameter_Specifications
(Decl_Node
, P_Parameter_Profile
);
881 if Is_Overriding
then
882 Set_Must_Override
(Decl_Node
);
883 elsif Not_Overriding
then
884 Set_Must_Not_Override
(Decl_Node
);
887 -- Error recovery check for illegal return
889 if Token
= Tok_Return
then
890 Error_Msg_SC
("entry cannot have return value!");
892 Discard_Junk_Node
(P_Subtype_Indication
);
895 -- Error recovery check for improper use of entry barrier in spec
897 if Token
= Tok_When
then
898 Error_Msg_SC
("barrier not allowed here (belongs in body)");
900 Discard_Junk_Node
(P_Expression_No_Right_Paren
);
908 Resync_Past_Semicolon
;
910 end P_Entry_Declaration
;
912 -----------------------------
913 -- 9.5.2 Accept Statement --
914 -----------------------------
916 -- ACCEPT_STATEMENT ::=
917 -- accept entry_DIRECT_NAME
918 -- [(ENTRY_INDEX)] PARAMETER_PROFILE [do
919 -- HANDLED_SEQUENCE_OF_STATEMENTS
920 -- end [entry_IDENTIFIER]];
922 -- The caller has checked that the initial token is ACCEPT
924 -- Error recovery: cannot raise Error_Resync. If an error occurs, the
925 -- scan is resynchronized past the next semicolon and control returns.
927 function P_Accept_Statement
return Node_Id
is
928 Scan_State
: Saved_Scan_State
;
929 Accept_Node
: Node_Id
;
934 Scope
.Table
(Scope
.Last
).Sloc
:= Token_Ptr
;
935 Scope
.Table
(Scope
.Last
).Ecol
:= Start_Column
;
937 Accept_Node
:= New_Node
(N_Accept_Statement
, Token_Ptr
);
939 Scope
.Table
(Scope
.Last
).Labl
:= Token_Node
;
941 Set_Entry_Direct_Name
(Accept_Node
, P_Identifier
(C_Do
));
943 -- Left paren could be (Entry_Index) or Formal_Part, determine which
945 if Token
= Tok_Left_Paren
then
946 Save_Scan_State
(Scan_State
); -- at left paren
947 Scan
; -- past left paren
949 -- If first token after left paren not identifier, then Entry_Index
951 if Token
/= Tok_Identifier
then
952 Set_Entry_Index
(Accept_Node
, P_Expression
);
954 Set_Parameter_Specifications
(Accept_Node
, P_Parameter_Profile
);
956 -- First token after left paren is identifier, could be either case
958 else -- Token = Tok_Identifier
959 Scan
; -- past identifier
961 -- If identifier followed by comma or colon, must be Formal_Part
963 if Token
= Tok_Comma
or else Token
= Tok_Colon
then
964 Restore_Scan_State
(Scan_State
); -- to left paren
965 Set_Parameter_Specifications
(Accept_Node
, P_Parameter_Profile
);
967 -- If identifier not followed by comma/colon, must be entry index
970 Restore_Scan_State
(Scan_State
); -- to left paren
971 Scan
; -- past left paren (again!)
972 Set_Entry_Index
(Accept_Node
, P_Expression
);
974 Set_Parameter_Specifications
(Accept_Node
, P_Parameter_Profile
);
979 -- Scan out DO if present
981 if Token
= Tok_Do
then
982 Scope
.Table
(Scope
.Last
).Etyp
:= E_Name
;
983 Scope
.Table
(Scope
.Last
).Lreq
:= False;
985 Hand_Seq
:= P_Handled_Sequence_Of_Statements
;
986 Set_Handled_Statement_Sequence
(Accept_Node
, Hand_Seq
);
987 End_Statements
(Handled_Statement_Sequence
(Accept_Node
));
989 -- Exception handlers not allowed in Ada 95 node
991 if Present
(Exception_Handlers
(Hand_Seq
)) then
992 if Ada_Version
= Ada_83
then
994 ("(Ada 83) exception handlers in accept not allowed",
995 First_Non_Pragma
(Exception_Handlers
(Hand_Seq
)));
1000 Pop_Scope_Stack
; -- discard unused entry
1006 -- If error, resynchronize past semicolon
1009 when Error_Resync
=>
1010 Resync_Past_Semicolon
;
1011 Pop_Scope_Stack
; -- discard unused entry
1014 end P_Accept_Statement
;
1016 ------------------------
1017 -- 9.5.2 Entry Index --
1018 ------------------------
1020 -- Parsed by P_Expression (4.4)
1022 -----------------------
1023 -- 9.5.2 Entry Body --
1024 -----------------------
1027 -- entry DEFINING_IDENTIFIER ENTRY_BODY_FORMAL_PART ENTRY_BARRIER is
1030 -- HANDLED_SEQUENCE_OF_STATEMENTS
1031 -- end [entry_IDENTIFIER];
1033 -- The caller has checked that the initial token is ENTRY
1035 -- Error_Recovery: cannot raise Error_Resync
1037 function P_Entry_Body
return Node_Id
is
1038 Entry_Node
: Node_Id
;
1039 Formal_Part_Node
: Node_Id
;
1040 Name_Node
: Node_Id
;
1044 Entry_Node
:= New_Node
(N_Entry_Body
, Token_Ptr
);
1047 Scope
.Table
(Scope
.Last
).Ecol
:= Start_Column
;
1048 Scope
.Table
(Scope
.Last
).Lreq
:= False;
1049 Scope
.Table
(Scope
.Last
).Etyp
:= E_Name
;
1051 Name_Node
:= P_Defining_Identifier
;
1052 Set_Defining_Identifier
(Entry_Node
, Name_Node
);
1053 Scope
.Table
(Scope
.Last
).Labl
:= Name_Node
;
1055 Formal_Part_Node
:= P_Entry_Body_Formal_Part
;
1056 Set_Entry_Body_Formal_Part
(Entry_Node
, Formal_Part_Node
);
1058 Set_Condition
(Formal_Part_Node
, P_Entry_Barrier
);
1059 Parse_Decls_Begin_End
(Entry_Node
);
1063 -----------------------------------
1064 -- 9.5.2 Entry Body Formal Part --
1065 -----------------------------------
1067 -- ENTRY_BODY_FORMAL_PART ::=
1068 -- [(ENTRY_INDEX_SPECIFICATION)] [PARAMETER_PART]
1070 -- Error_Recovery: cannot raise Error_Resync
1072 function P_Entry_Body_Formal_Part
return Node_Id
is
1073 Fpart_Node
: Node_Id
;
1074 Scan_State
: Saved_Scan_State
;
1077 Fpart_Node
:= New_Node
(N_Entry_Body_Formal_Part
, Token_Ptr
);
1079 -- See if entry index specification present, and if so parse it
1081 if Token
= Tok_Left_Paren
then
1082 Save_Scan_State
(Scan_State
); -- at left paren
1083 Scan
; -- past left paren
1085 if Token
= Tok_For
then
1086 Set_Entry_Index_Specification
1087 (Fpart_Node
, P_Entry_Index_Specification
);
1090 Restore_Scan_State
(Scan_State
); -- to left paren
1093 -- Check for (common?) case of left paren omitted before FOR. This
1094 -- is a tricky case, because the corresponding missing left paren
1095 -- can cause real havoc if a formal part is present which gets
1096 -- treated as part of the discrete subtype definition of the
1097 -- entry index specification, so just give error and resynchronize
1099 elsif Token
= Tok_For
then
1100 T_Left_Paren
; -- to give error message
1104 Set_Parameter_Specifications
(Fpart_Node
, P_Parameter_Profile
);
1106 end P_Entry_Body_Formal_Part
;
1108 --------------------------
1109 -- 9.5.2 Entry Barrier --
1110 --------------------------
1112 -- ENTRY_BARRIER ::= when CONDITION
1114 -- Error_Recovery: cannot raise Error_Resync
1116 function P_Entry_Barrier
return Node_Id
is
1120 if Token
= Tok_When
then
1122 Bnode
:= P_Expression_No_Right_Paren
;
1124 if Token
= Tok_Colon_Equal
then
1125 Error_Msg_SC
-- CODEFIX
1126 ("|"":="" should be ""=""");
1128 Bnode
:= P_Expression_No_Right_Paren
;
1132 T_When
; -- to give error message
1138 end P_Entry_Barrier
;
1140 --------------------------------------
1141 -- 9.5.2 Entry Index Specification --
1142 --------------------------------------
1144 -- ENTRY_INDEX_SPECIFICATION ::=
1145 -- for DEFINING_IDENTIFIER in DISCRETE_SUBTYPE_DEFINITION
1147 -- Error recovery: can raise Error_Resync
1149 function P_Entry_Index_Specification
return Node_Id
is
1150 Iterator_Node
: Node_Id
;
1153 Iterator_Node
:= New_Node
(N_Entry_Index_Specification
, Token_Ptr
);
1155 Set_Defining_Identifier
(Iterator_Node
, P_Defining_Identifier
(C_In
));
1157 Set_Discrete_Subtype_Definition
1158 (Iterator_Node
, P_Discrete_Subtype_Definition
);
1159 return Iterator_Node
;
1160 end P_Entry_Index_Specification
;
1162 ---------------------------------
1163 -- 9.5.3 Entry Call Statement --
1164 ---------------------------------
1166 -- Parsed by P_Name (4.1). Within a select, an entry call is parsed
1167 -- by P_Select_Statement (9.7)
1169 ------------------------------
1170 -- 9.5.4 Requeue Statement --
1171 ------------------------------
1173 -- REQUEUE_STATEMENT ::= requeue entry_NAME [with abort];
1175 -- The caller has checked that the initial token is requeue
1177 -- Error recovery: can raise Error_Resync
1179 function P_Requeue_Statement
return Node_Id
is
1180 Requeue_Node
: Node_Id
;
1183 Requeue_Node
:= New_Node
(N_Requeue_Statement
, Token_Ptr
);
1184 Scan
; -- past REQUEUE
1185 Set_Name
(Requeue_Node
, P_Name
);
1187 if Token
= Tok_With
then
1190 Set_Abort_Present
(Requeue_Node
, True);
1194 return Requeue_Node
;
1195 end P_Requeue_Statement
;
1197 --------------------------
1198 -- 9.6 Delay Statement --
1199 --------------------------
1201 -- DELAY_STATEMENT ::=
1202 -- DELAY_UNTIL_STATEMENT
1203 -- | DELAY_RELATIVE_STATEMENT
1205 -- The caller has checked that the initial token is DELAY
1207 -- Error recovery: cannot raise Error_Resync
1209 function P_Delay_Statement
return Node_Id
is
1213 -- The following check for delay until misused in Ada 83 doesn't catch
1214 -- all cases, but it's good enough to catch most of them!
1216 if Token_Name
= Name_Until
then
1217 Check_95_Keyword
(Tok_Until
, Tok_Left_Paren
);
1218 Check_95_Keyword
(Tok_Until
, Tok_Identifier
);
1221 if Token
= Tok_Until
then
1222 return P_Delay_Until_Statement
;
1224 return P_Delay_Relative_Statement
;
1226 end P_Delay_Statement
;
1228 --------------------------------
1229 -- 9.6 Delay Until Statement --
1230 --------------------------------
1232 -- DELAY_UNTIL_STATEMENT ::= delay until delay_EXPRESSION;
1234 -- The caller has checked that the initial token is DELAY, scanned it
1235 -- out and checked that the current token is UNTIL
1237 -- Error recovery: cannot raise Error_Resync
1239 function P_Delay_Until_Statement
return Node_Id
is
1240 Delay_Node
: Node_Id
;
1243 Delay_Node
:= New_Node
(N_Delay_Until_Statement
, Prev_Token_Ptr
);
1245 Set_Expression
(Delay_Node
, P_Expression_No_Right_Paren
);
1248 end P_Delay_Until_Statement
;
1250 -----------------------------------
1251 -- 9.6 Delay Relative Statement --
1252 -----------------------------------
1254 -- DELAY_RELATIVE_STATEMENT ::= delay delay_EXPRESSION;
1256 -- The caller has checked that the initial token is DELAY, scanned it
1257 -- out and determined that the current token is not UNTIL
1259 -- Error recovery: cannot raise Error_Resync
1261 function P_Delay_Relative_Statement
return Node_Id
is
1262 Delay_Node
: Node_Id
;
1265 Delay_Node
:= New_Node
(N_Delay_Relative_Statement
, Prev_Token_Ptr
);
1266 Set_Expression
(Delay_Node
, P_Expression_No_Right_Paren
);
1267 Check_Simple_Expression_In_Ada_83
(Expression
(Delay_Node
));
1270 end P_Delay_Relative_Statement
;
1272 ---------------------------
1273 -- 9.7 Select Statement --
1274 ---------------------------
1276 -- SELECT_STATEMENT ::=
1278 -- | TIMED_ENTRY_CALL
1279 -- | CONDITIONAL_ENTRY_CALL
1280 -- | ASYNCHRONOUS_SELECT
1282 -- SELECTIVE_ACCEPT ::=
1285 -- SELECT_ALTERNATIVE
1288 -- SELECT_ALTERNATIVE
1290 -- SEQUENCE_OF_STATEMENTS]
1293 -- GUARD ::= when CONDITION =>
1295 -- Note: the guard preceding a select alternative is included as part
1296 -- of the node generated for a selective accept alternative.
1298 -- SELECT_ALTERNATIVE ::=
1299 -- ACCEPT_ALTERNATIVE
1300 -- | DELAY_ALTERNATIVE
1301 -- | TERMINATE_ALTERNATIVE
1303 -- TIMED_ENTRY_CALL ::=
1305 -- ENTRY_CALL_ALTERNATIVE
1307 -- DELAY_ALTERNATIVE
1310 -- CONDITIONAL_ENTRY_CALL ::=
1312 -- ENTRY_CALL_ALTERNATIVE
1314 -- SEQUENCE_OF_STATEMENTS
1317 -- ENTRY_CALL_ALTERNATIVE ::=
1318 -- ENTRY_CALL_STATEMENT [SEQUENCE_OF_STATEMENTS]
1320 -- ASYNCHRONOUS_SELECT ::=
1322 -- TRIGGERING_ALTERNATIVE
1327 -- TRIGGERING_ALTERNATIVE ::=
1328 -- TRIGGERING_STATEMENT [SEQUENCE_OF_STATEMENTS]
1330 -- TRIGGERING_STATEMENT ::= ENTRY_CALL_STATEMENT | DELAY_STATEMENT
1332 -- The caller has checked that the initial token is SELECT
1334 -- Error recovery: can raise Error_Resync
1336 function P_Select_Statement
return Node_Id
is
1337 Select_Node
: Node_Id
;
1338 Select_Sloc
: Source_Ptr
;
1339 Stmnt_Sloc
: Source_Ptr
;
1340 Ecall_Node
: Node_Id
;
1341 Alternative
: Node_Id
;
1342 Select_Pragmas
: List_Id
;
1343 Alt_Pragmas
: List_Id
;
1344 Statement_List
: List_Id
;
1346 Cond_Expr
: Node_Id
;
1347 Delay_Stmnt
: Node_Id
;
1351 Scope
.Table
(Scope
.Last
).Etyp
:= E_Select
;
1352 Scope
.Table
(Scope
.Last
).Ecol
:= Start_Column
;
1353 Scope
.Table
(Scope
.Last
).Sloc
:= Token_Ptr
;
1354 Scope
.Table
(Scope
.Last
).Labl
:= Error
;
1356 Select_Sloc
:= Token_Ptr
;
1357 Scan
; -- past SELECT
1358 Stmnt_Sloc
:= Token_Ptr
;
1359 Select_Pragmas
:= P_Pragmas_Opt
;
1361 -- If first token after select is designator, then we have an entry
1362 -- call, which must be the start of a conditional entry call, timed
1363 -- entry call or asynchronous select
1365 if Token
in Token_Class_Desig
then
1367 -- Scan entry call statement
1370 Ecall_Node
:= P_Name
;
1372 -- ?? The following two clauses exactly parallel code in ch5
1373 -- and should be combined sometime
1375 if Nkind
(Ecall_Node
) = N_Indexed_Component
then
1377 Prefix_Node
: constant Node_Id
:= Prefix
(Ecall_Node
);
1378 Exprs_Node
: constant List_Id
:= Expressions
(Ecall_Node
);
1381 Change_Node
(Ecall_Node
, N_Procedure_Call_Statement
);
1382 Set_Name
(Ecall_Node
, Prefix_Node
);
1383 Set_Parameter_Associations
(Ecall_Node
, Exprs_Node
);
1386 elsif Nkind
(Ecall_Node
) = N_Function_Call
then
1388 Fname_Node
: constant Node_Id
:= Name
(Ecall_Node
);
1389 Params_List
: constant List_Id
:=
1390 Parameter_Associations
(Ecall_Node
);
1393 Change_Node
(Ecall_Node
, N_Procedure_Call_Statement
);
1394 Set_Name
(Ecall_Node
, Fname_Node
);
1395 Set_Parameter_Associations
(Ecall_Node
, Params_List
);
1398 elsif Nkind
(Ecall_Node
) = N_Identifier
1399 or else Nkind
(Ecall_Node
) = N_Selected_Component
1401 -- Case of a call to a parameterless entry
1404 C_Node
: constant Node_Id
:=
1405 New_Node
(N_Procedure_Call_Statement
, Stmnt_Sloc
);
1407 Set_Name
(C_Node
, Ecall_Node
);
1408 Set_Parameter_Associations
(C_Node
, No_List
);
1409 Ecall_Node
:= C_Node
;
1416 when Error_Resync
=>
1417 Resync_Past_Semicolon
;
1421 Statement_List
:= P_Sequence_Of_Statements
(SS_Eltm_Ortm_Tatm
);
1423 -- OR follows, we have a timed entry call
1425 if Token
= Tok_Or
then
1427 Alt_Pragmas
:= P_Pragmas_Opt
;
1429 Select_Node
:= New_Node
(N_Timed_Entry_Call
, Select_Sloc
);
1430 Set_Entry_Call_Alternative
(Select_Node
,
1431 Make_Entry_Call_Alternative
(Stmnt_Sloc
,
1432 Entry_Call_Statement
=> Ecall_Node
,
1433 Pragmas_Before
=> Select_Pragmas
,
1434 Statements
=> Statement_List
));
1436 -- Only possibility is delay alternative. If we have anything
1437 -- else, give message, and treat as conditional entry call.
1439 if Token
/= Tok_Delay
then
1441 ("only allowed alternative in timed entry call is delay!");
1442 Discard_Junk_List
(P_Sequence_Of_Statements
(SS_Sreq
));
1443 Set_Delay_Alternative
(Select_Node
, Error
);
1446 Set_Delay_Alternative
(Select_Node
, P_Delay_Alternative
);
1448 (Delay_Alternative
(Select_Node
), Alt_Pragmas
);
1451 -- ELSE follows, we have a conditional entry call
1453 elsif Token
= Tok_Else
then
1455 Select_Node
:= New_Node
(N_Conditional_Entry_Call
, Select_Sloc
);
1457 Set_Entry_Call_Alternative
(Select_Node
,
1458 Make_Entry_Call_Alternative
(Stmnt_Sloc
,
1459 Entry_Call_Statement
=> Ecall_Node
,
1460 Pragmas_Before
=> Select_Pragmas
,
1461 Statements
=> Statement_List
));
1464 (Select_Node
, P_Sequence_Of_Statements
(SS_Sreq
));
1466 -- Only remaining case is THEN ABORT (asynchronous select)
1468 elsif Token
= Tok_Abort
then
1470 Make_Asynchronous_Select
(Select_Sloc
,
1471 Triggering_Alternative
=>
1472 Make_Triggering_Alternative
(Stmnt_Sloc
,
1473 Triggering_Statement
=> Ecall_Node
,
1474 Pragmas_Before
=> Select_Pragmas
,
1475 Statements
=> Statement_List
),
1476 Abortable_Part
=> P_Abortable_Part
);
1481 if Ada_Version
= Ada_83
then
1482 Error_Msg_BC
("OR or ELSE expected");
1484 Error_Msg_BC
("OR or ELSE or THEN ABORT expected");
1487 Select_Node
:= Error
;
1492 -- Here we have a selective accept or an asynchronous select (first
1493 -- token after SELECT is other than a designator token).
1496 -- If we have delay with no guard, could be asynchronous select
1498 if Token
= Tok_Delay
then
1499 Delay_Stmnt
:= P_Delay_Statement
;
1500 Statement_List
:= P_Sequence_Of_Statements
(SS_Eltm_Ortm_Tatm
);
1502 -- Asynchronous select
1504 if Token
= Tok_Abort
then
1506 Make_Asynchronous_Select
(Select_Sloc
,
1507 Triggering_Alternative
=>
1508 Make_Triggering_Alternative
(Stmnt_Sloc
,
1509 Triggering_Statement
=> Delay_Stmnt
,
1510 Pragmas_Before
=> Select_Pragmas
,
1511 Statements
=> Statement_List
),
1512 Abortable_Part
=> P_Abortable_Part
);
1517 -- Delay which was not an asynchronous select. Must be a selective
1518 -- accept, and since at least one accept statement is required,
1519 -- we must have at least one OR phrase present.
1522 Alt_List
:= New_List
(
1523 Make_Delay_Alternative
(Stmnt_Sloc
,
1524 Delay_Statement
=> Delay_Stmnt
,
1525 Pragmas_Before
=> Select_Pragmas
,
1526 Statements
=> Statement_List
));
1528 Alt_Pragmas
:= P_Pragmas_Opt
;
1531 -- If not a delay statement, then must be another possibility for
1532 -- a selective accept alternative, or perhaps a guard is present
1535 Alt_List
:= New_List
;
1536 Alt_Pragmas
:= Select_Pragmas
;
1539 Select_Node
:= New_Node
(N_Selective_Accept
, Select_Sloc
);
1540 Set_Select_Alternatives
(Select_Node
, Alt_List
);
1542 -- Scan out selective accept alternatives. On entry to this loop,
1543 -- we are just past a SELECT or OR token, and any pragmas that
1544 -- immediately follow the SELECT or OR are in Alt_Pragmas.
1547 if Token
= Tok_When
then
1549 if Present
(Alt_Pragmas
) then
1550 Error_Msg_SC
("pragmas may not precede guard");
1554 Cond_Expr
:= P_Expression_No_Right_Paren
;
1556 Alt_Pragmas
:= P_Pragmas_Opt
;
1562 if Token
= Tok_Accept
then
1563 Alternative
:= P_Accept_Alternative
;
1565 -- Check for junk attempt at asynchronous select using
1566 -- an Accept alternative as the triggering statement
1568 if Token
= Tok_Abort
1569 and then Is_Empty_List
(Alt_List
)
1570 and then No
(Cond_Expr
)
1573 ("triggering statement must be entry call or delay",
1574 Sloc
(Alternative
));
1575 Scan
; -- past junk ABORT
1576 Discard_Junk_List
(P_Sequence_Of_Statements
(SS_Sreq
));
1581 elsif Token
= Tok_Delay
then
1582 Alternative
:= P_Delay_Alternative
;
1584 elsif Token
= Tok_Terminate
then
1585 Alternative
:= P_Terminate_Alternative
;
1589 ("select alternative (ACCEPT, ABORT, DELAY) expected");
1590 Alternative
:= Error
;
1592 if Token
= Tok_Semicolon
then
1593 Scan
; -- past junk semicolon
1597 -- THEN ABORT at this stage is just junk
1599 if Token
= Tok_Abort
then
1600 Error_Msg_SP
("misplaced `THEN ABORT`");
1601 Scan
; -- past junk ABORT
1602 Discard_Junk_List
(P_Sequence_Of_Statements
(SS_Sreq
));
1607 if Alternative
/= Error
then
1608 Set_Condition
(Alternative
, Cond_Expr
);
1609 Set_Pragmas_Before
(Alternative
, Alt_Pragmas
);
1610 Append
(Alternative
, Alt_List
);
1613 exit when Token
/= Tok_Or
;
1617 Alt_Pragmas
:= P_Pragmas_Opt
;
1620 if Token
= Tok_Else
then
1623 (Select_Node
, P_Sequence_Of_Statements
(SS_Ortm_Sreq
));
1625 if Token
= Tok_Or
then
1626 Error_Msg_SC
("select alternative cannot follow else part!");
1634 end P_Select_Statement
;
1636 -----------------------------
1637 -- 9.7.1 Selective Accept --
1638 -----------------------------
1640 -- Parsed by P_Select_Statement (9.7)
1646 -- Parsed by P_Select_Statement (9.7)
1648 -------------------------------
1649 -- 9.7.1 Select Alternative --
1650 -------------------------------
1652 -- SELECT_ALTERNATIVE ::=
1653 -- ACCEPT_ALTERNATIVE
1654 -- | DELAY_ALTERNATIVE
1655 -- | TERMINATE_ALTERNATIVE
1657 -- Note: the guard preceding a select alternative is included as part
1658 -- of the node generated for a selective accept alternative.
1660 -- Error recovery: cannot raise Error_Resync
1662 -------------------------------
1663 -- 9.7.1 Accept Alternative --
1664 -------------------------------
1666 -- ACCEPT_ALTERNATIVE ::=
1667 -- ACCEPT_STATEMENT [SEQUENCE_OF_STATEMENTS]
1669 -- Error_Recovery: Cannot raise Error_Resync
1671 -- Note: the caller is responsible for setting the Pragmas_Before
1672 -- field of the returned N_Terminate_Alternative node.
1674 function P_Accept_Alternative
return Node_Id
is
1675 Accept_Alt_Node
: Node_Id
;
1678 Accept_Alt_Node
:= New_Node
(N_Accept_Alternative
, Token_Ptr
);
1679 Set_Accept_Statement
(Accept_Alt_Node
, P_Accept_Statement
);
1681 -- Note: the reason that we accept THEN ABORT as a terminator for
1682 -- the sequence of statements is for error recovery which allows
1683 -- for misuse of an accept statement as a triggering statement.
1686 (Accept_Alt_Node
, P_Sequence_Of_Statements
(SS_Eltm_Ortm_Tatm
));
1687 return Accept_Alt_Node
;
1688 end P_Accept_Alternative
;
1690 ------------------------------
1691 -- 9.7.1 Delay Alternative --
1692 ------------------------------
1694 -- DELAY_ALTERNATIVE ::=
1695 -- DELAY_STATEMENT [SEQUENCE_OF_STATEMENTS]
1697 -- Error_Recovery: Cannot raise Error_Resync
1699 -- Note: the caller is responsible for setting the Pragmas_Before
1700 -- field of the returned N_Terminate_Alternative node.
1702 function P_Delay_Alternative
return Node_Id
is
1703 Delay_Alt_Node
: Node_Id
;
1706 Delay_Alt_Node
:= New_Node
(N_Delay_Alternative
, Token_Ptr
);
1707 Set_Delay_Statement
(Delay_Alt_Node
, P_Delay_Statement
);
1709 -- Note: the reason that we accept THEN ABORT as a terminator for
1710 -- the sequence of statements is for error recovery which allows
1711 -- for misuse of an accept statement as a triggering statement.
1714 (Delay_Alt_Node
, P_Sequence_Of_Statements
(SS_Eltm_Ortm_Tatm
));
1715 return Delay_Alt_Node
;
1716 end P_Delay_Alternative
;
1718 ----------------------------------
1719 -- 9.7.1 Terminate Alternative --
1720 ----------------------------------
1722 -- TERMINATE_ALTERNATIVE ::= terminate;
1724 -- Error_Recovery: Cannot raise Error_Resync
1726 -- Note: the caller is responsible for setting the Pragmas_Before
1727 -- field of the returned N_Terminate_Alternative node.
1729 function P_Terminate_Alternative
return Node_Id
is
1730 Terminate_Alt_Node
: Node_Id
;
1733 Terminate_Alt_Node
:= New_Node
(N_Terminate_Alternative
, Token_Ptr
);
1734 Scan
; -- past TERMINATE
1737 -- For all other select alternatives, the sequence of statements
1738 -- after the alternative statement will swallow up any pragmas
1739 -- coming in this position. But the terminate alternative has no
1740 -- sequence of statements, so the pragmas here must be treated
1743 Set_Pragmas_After
(Terminate_Alt_Node
, P_Pragmas_Opt
);
1744 return Terminate_Alt_Node
;
1745 end P_Terminate_Alternative
;
1747 -----------------------------
1748 -- 9.7.2 Timed Entry Call --
1749 -----------------------------
1751 -- Parsed by P_Select_Statement (9.7)
1753 -----------------------------------
1754 -- 9.7.2 Entry Call Alternative --
1755 -----------------------------------
1757 -- Parsed by P_Select_Statement (9.7)
1759 -----------------------------------
1760 -- 9.7.3 Conditional Entry Call --
1761 -----------------------------------
1763 -- Parsed by P_Select_Statement (9.7)
1765 --------------------------------
1766 -- 9.7.4 Asynchronous Select --
1767 --------------------------------
1769 -- Parsed by P_Select_Statement (9.7)
1771 -----------------------------------
1772 -- 9.7.4 Triggering Alternative --
1773 -----------------------------------
1775 -- Parsed by P_Select_Statement (9.7)
1777 ---------------------------------
1778 -- 9.7.4 Triggering Statement --
1779 ---------------------------------
1781 -- Parsed by P_Select_Statement (9.7)
1783 ---------------------------
1784 -- 9.7.4 Abortable Part --
1785 ---------------------------
1787 -- ABORTABLE_PART ::= SEQUENCE_OF_STATEMENTS
1789 -- The caller has verified that THEN ABORT is present, and Token is
1790 -- pointing to the ABORT on entry (or if not, then we have an error)
1792 -- Error recovery: cannot raise Error_Resync
1794 function P_Abortable_Part
return Node_Id
is
1795 Abortable_Part_Node
: Node_Id
;
1798 Abortable_Part_Node
:= New_Node
(N_Abortable_Part
, Token_Ptr
);
1799 T_Abort
; -- scan past ABORT
1801 if Ada_Version
= Ada_83
then
1802 Error_Msg_SP
("(Ada 83) asynchronous select not allowed!");
1805 Set_Statements
(Abortable_Part_Node
, P_Sequence_Of_Statements
(SS_Sreq
));
1806 return Abortable_Part_Node
;
1807 end P_Abortable_Part
;
1809 --------------------------
1810 -- 9.8 Abort Statement --
1811 --------------------------
1813 -- ABORT_STATEMENT ::= abort task_NAME {, task_NAME};
1815 -- The caller has checked that the initial token is ABORT
1817 -- Error recovery: cannot raise Error_Resync
1819 function P_Abort_Statement
return Node_Id
is
1820 Abort_Node
: Node_Id
;
1823 Abort_Node
:= New_Node
(N_Abort_Statement
, Token_Ptr
);
1825 Set_Names
(Abort_Node
, New_List
);
1828 Append
(P_Name
, Names
(Abort_Node
));
1829 exit when Token
/= Tok_Comma
;
1835 end P_Abort_Statement
;