1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2002 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 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 pragma Style_Checks (All_Checks);
28 -- Turn off subprogram body ordering check. Subprograms are in order
29 -- by RM section rather than alphabetical
34 -- Local subprograms, used only in this chapter
36 function P_Accept_Alternative return Node_Id;
37 function P_Delay_Alternative return Node_Id;
38 function P_Delay_Relative_Statement return Node_Id;
39 function P_Delay_Until_Statement return Node_Id;
40 function P_Entry_Barrier return Node_Id;
41 function P_Entry_Body_Formal_Part return Node_Id;
42 function P_Entry_Declaration return Node_Id;
43 function P_Entry_Index_Specification return Node_Id;
44 function P_Protected_Definition return Node_Id;
45 function P_Protected_Operation_Declaration_Opt return Node_Id;
46 function P_Protected_Operation_Items return List_Id;
47 function P_Task_Definition return Node_Id;
48 function P_Task_Items return List_Id;
50 -----------------------------
51 -- 9.1 Task (also 10.1.3) --
52 -----------------------------
54 -- TASK_TYPE_DECLARATION ::=
55 -- task type DEFINING_IDENTIFIER [KNOWN_DISCRIMINANT_PART]
56 -- [is TASK_DEFINITION];
58 -- SINGLE_TASK_DECLARATION ::=
59 -- task DEFINING_IDENTIFIER [is 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;
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;
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);
147 -- Parse optional task definition. Note that P_Task_Definition scans
148 -- out the semicolon as well as the task definition itself.
150 if Token = Tok_Semicolon then
152 -- A little check, if the next token after semicolon is
153 -- Entry, then surely the semicolon should really be IS
155 Scan; -- past semicolon
157 if Token = Tok_Entry then
158 Error_Msg_SP (""";"" 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
165 Set_Task_Definition (Task_Node, P_Task_Definition);
172 --------------------------------
173 -- 9.1 Task Type Declaration --
174 --------------------------------
176 -- Parsed by P_Task (9.1)
178 ----------------------------------
179 -- 9.1 Single Task Declaration --
180 ----------------------------------
182 -- Parsed by P_Task (9.1)
184 --------------------------
185 -- 9.1 Task Definition --
186 --------------------------
188 -- TASK_DEFINITION ::=
192 -- end [task_IDENTIFIER];
194 -- The caller has already made the scope stack entry
196 -- Note: there is a small deviation from official syntax here in that we
197 -- regard the semicolon after end as part of the Task_Definition, and in
198 -- the official syntax, it's part of the enclosing declaration. The reason
199 -- for this deviation is that otherwise the end processing would have to
200 -- be special cased, which would be a nuisance!
202 -- Error recovery: cannot raise Error_Resync
204 function P_Task_Definition return Node_Id is
208 Def_Node := New_Node (N_Task_Definition, Token_Ptr);
209 Set_Visible_Declarations (Def_Node, P_Task_Items);
211 if Token = Tok_Private then
212 Scan; -- past PRIVATE
213 Set_Private_Declarations (Def_Node, P_Task_Items);
215 -- Deal gracefully with multiple PRIVATE parts
217 while Token = Tok_Private loop
218 Error_Msg_SC ("Only one private part allowed per task");
219 Scan; -- past PRIVATE
220 Append_List (P_Task_Items, Private_Declarations (Def_Node));
224 End_Statements (Def_Node);
226 end P_Task_Definition;
232 -- TASK_ITEM ::= ENTRY_DECLARATION | REPRESENTATION_CLAUSE
234 -- This subprogram scans a (possibly empty) list of task items and pragmas
236 -- Error recovery: cannot raise Error_Resync
238 -- Note: a pragma can also be returned in this position
240 function P_Task_Items return List_Id is
243 Decl_Sloc : Source_Ptr;
246 -- Get rid of active SIS entry from outer scope. This means we will
247 -- miss some nested cases, but it doesn't seem worth the effort. See
248 -- discussion in Par for further details
250 SIS_Entry_Active := False;
252 -- Loop to scan out task items
257 Decl_Sloc := Token_Ptr;
259 if Token = Tok_Pragma then
260 Append (P_Pragma, Items);
262 elsif Token = Tok_Entry then
263 Append (P_Entry_Declaration, Items);
265 elsif Token = Tok_For then
266 -- Representation clause in task declaration. The only rep
267 -- clause which is legal in a protected is an address clause,
268 -- so that is what we try to scan out.
270 Item_Node := P_Representation_Clause;
272 if Nkind (Item_Node) = N_At_Clause then
273 Append (Item_Node, Items);
275 elsif Nkind (Item_Node) = N_Attribute_Definition_Clause
276 and then Chars (Item_Node) = Name_Address
278 Append (Item_Node, Items);
282 ("the only representation clause " &
283 "allowed here is an address clause!", Decl_Sloc);
286 elsif Token = Tok_Identifier
287 or else Token in Token_Class_Declk
289 Error_Msg_SC ("Illegal declaration in task definition");
290 Resync_Past_Semicolon;
304 -- Parsed by P_Task (9.1)
306 ----------------------------------
307 -- 9.4 Protected (also 10.1.3) --
308 ----------------------------------
310 -- PROTECTED_TYPE_DECLARATION ::=
311 -- protected type DEFINING_IDENTIFIER [KNOWN_DISCRIMINANT_PART]
312 -- is PROTECTED_DEFINITION;
314 -- SINGLE_PROTECTED_DECLARATION ::=
315 -- protected DEFINING_IDENTIFIER is PROTECTED_DEFINITION;
317 -- PROTECTED_BODY ::=
318 -- protected body DEFINING_IDENTIFIER is
319 -- {PROTECTED_OPERATION_ITEM}
320 -- end [protected_IDENTIFIER];
322 -- PROTECTED_BODY_STUB ::=
323 -- protected body DEFINING_IDENTIFIER is separate;
325 -- This routine scans out a protected declaration, protected body
326 -- or a protected stub.
328 -- The caller has checked that the initial token is PROTECTED and
329 -- scanned past it, so Token is set to the following token.
331 -- Error recovery: cannot raise Error_Resync
333 function P_Protected return Node_Id is
335 Protected_Node : Node_Id;
336 Protected_Sloc : Source_Ptr;
340 Scope.Table (Scope.Last).Etyp := E_Name;
341 Scope.Table (Scope.Last).Ecol := Start_Column;
342 Scope.Table (Scope.Last).Lreq := False;
343 Protected_Sloc := Prev_Token_Ptr;
345 if Token = Tok_Body then
347 Name_Node := P_Defining_Identifier;
348 Scope.Table (Scope.Last).Labl := Name_Node;
350 if Token = Tok_Left_Paren then
351 Error_Msg_SC ("discriminant part not allowed in protected body");
352 Discard_Junk_List (P_Known_Discriminant_Part_Opt);
359 if Token = Tok_Separate then
360 Scan; -- past SEPARATE
361 Protected_Node := New_Node (N_Protected_Body_Stub, Protected_Sloc);
362 Set_Defining_Identifier (Protected_Node, Name_Node);
364 Pop_Scope_Stack; -- remove unused entry
369 Protected_Node := New_Node (N_Protected_Body, Protected_Sloc);
370 Set_Defining_Identifier (Protected_Node, Name_Node);
371 Set_Declarations (Protected_Node, P_Protected_Operation_Items);
372 End_Statements (Protected_Node);
375 return Protected_Node;
377 -- Otherwise we must have a protected declaration
380 if Token = Tok_Type then
383 New_Node (N_Protected_Type_Declaration, Protected_Sloc);
384 Name_Node := P_Defining_Identifier;
385 Set_Defining_Identifier (Protected_Node, Name_Node);
386 Scope.Table (Scope.Last).Labl := Name_Node;
387 Set_Discriminant_Specifications
388 (Protected_Node, P_Known_Discriminant_Part_Opt);
392 New_Node (N_Single_Protected_Declaration, Protected_Sloc);
393 Name_Node := P_Defining_Identifier;
394 Set_Defining_Identifier (Protected_Node, Name_Node);
396 if Token = Tok_Left_Paren then
398 ("discriminant part not allowed for single protected");
399 Discard_Junk_List (P_Known_Discriminant_Part_Opt);
402 Scope.Table (Scope.Last).Labl := Name_Node;
406 Set_Protected_Definition (Protected_Node, P_Protected_Definition);
407 return Protected_Node;
411 -------------------------------------
412 -- 9.4 Protected Type Declaration --
413 -------------------------------------
415 -- Parsed by P_Protected (9.4)
417 ---------------------------------------
418 -- 9.4 Single Protected Declaration --
419 ---------------------------------------
421 -- Parsed by P_Protected (9.4)
423 -------------------------------
424 -- 9.4 Protected Definition --
425 -------------------------------
427 -- PROTECTED_DEFINITION ::=
428 -- {PROTECTED_OPERATION_DECLARATION}
430 -- {PROTECTED_ELEMENT_DECLARATION}]
431 -- end [protected_IDENTIFIER]
433 -- PROTECTED_ELEMENT_DECLARATION ::=
434 -- PROTECTED_OPERATION_DECLARATION
435 -- | COMPONENT_DECLARATION
437 -- The caller has already established the scope stack entry
439 -- Error recovery: cannot raise Error_Resync
441 function P_Protected_Definition return Node_Id is
446 Def_Node := New_Node (N_Protected_Definition, Token_Ptr);
448 -- Get rid of active SIS entry from outer scope. This means we will
449 -- miss some nested cases, but it doesn't seem worth the effort. See
450 -- discussion in Par for further details
452 SIS_Entry_Active := False;
454 -- Loop to scan visible declarations (protected operation declarations)
456 Set_Visible_Declarations (Def_Node, New_List);
459 Item_Node := P_Protected_Operation_Declaration_Opt;
460 exit when No (Item_Node);
461 Append (Item_Node, Visible_Declarations (Def_Node));
464 -- Deal with PRIVATE part (including graceful handling
465 -- of multiple PRIVATE parts).
467 Private_Loop : while Token = Tok_Private loop
468 if No (Private_Declarations (Def_Node)) then
469 Set_Private_Declarations (Def_Node, New_List);
471 Error_Msg_SC ("duplicate private part");
474 Scan; -- past PRIVATE
476 Declaration_Loop : loop
477 if Token = Tok_Identifier then
478 P_Component_Items (Private_Declarations (Def_Node));
480 Item_Node := P_Protected_Operation_Declaration_Opt;
481 exit Declaration_Loop when No (Item_Node);
482 Append (Item_Node, Private_Declarations (Def_Node));
484 end loop Declaration_Loop;
485 end loop Private_Loop;
487 End_Statements (Def_Node);
489 end P_Protected_Definition;
491 ------------------------------------------
492 -- 9.4 Protected Operation Declaration --
493 ------------------------------------------
495 -- PROTECTED_OPERATION_DECLARATION ::=
496 -- SUBPROGRAM_DECLARATION
497 -- | ENTRY_DECLARATION
498 -- | REPRESENTATION_CLAUSE
500 -- Error recovery: cannot raise Error_Resync
502 -- Note: a pragma can also be returned in this position
504 -- We are not currently permitting representation clauses to appear as
505 -- protected operation declarations, do we have to rethink this???
507 function P_Protected_Operation_Declaration_Opt return Node_Id is
512 -- This loop runs more than once only when a junk declaration
516 if Token = Tok_Pragma then
519 elsif Token = Tok_Entry then
520 return P_Entry_Declaration;
522 elsif Token = Tok_Function or else Token = Tok_Procedure then
523 return P_Subprogram (Pf_Decl);
525 elsif Token = Tok_Identifier then
528 Skip_Declaration (L);
530 if Nkind (First (L)) = N_Object_Declaration then
532 ("component must be declared in private part of " &
533 "protected type", P);
536 ("illegal declaration in protected definition", P);
539 elsif Token in Token_Class_Declk then
540 Error_Msg_SC ("illegal declaration in protected definition");
541 Resync_Past_Semicolon;
543 -- Return now to avoid cascaded messages if next declaration
544 -- is a valid component declaration.
548 elsif Token = Tok_For then
550 ("representation clause not allowed in protected definition");
551 Resync_Past_Semicolon;
557 end P_Protected_Operation_Declaration_Opt;
559 -----------------------------------
560 -- 9.4 Protected Operation Item --
561 -----------------------------------
563 -- PROTECTED_OPERATION_ITEM ::=
564 -- SUBPROGRAM_DECLARATION
567 -- | REPRESENTATION_CLAUSE
569 -- This procedure parses and returns a list of protected operation items
571 -- We are not currently permitting representation clauses to appear
572 -- as protected operation items, do we have to rethink this???
574 function P_Protected_Operation_Items return List_Id is
578 Item_List := New_List;
581 if Token = Tok_Entry or else Bad_Spelling_Of (Tok_Entry) then
582 Append (P_Entry_Body, Item_List);
584 elsif Token = Tok_Function or else Bad_Spelling_Of (Tok_Function)
586 Token = Tok_Procedure or else Bad_Spelling_Of (Tok_Procedure)
588 Append (P_Subprogram (Pf_Decl_Pbod), Item_List);
590 elsif Token = Tok_Pragma or else Bad_Spelling_Of (Tok_Pragma) then
591 P_Pragmas_Opt (Item_List);
593 elsif Token = Tok_Private or else Bad_Spelling_Of (Tok_Private) then
594 Error_Msg_SC ("PRIVATE not allowed in protected body");
595 Scan; -- past PRIVATE
597 elsif Token = Tok_Identifier then
599 ("all components must be declared in spec!");
600 Resync_Past_Semicolon;
602 elsif Token in Token_Class_Declk then
603 Error_Msg_SC ("this declaration not allowed in protected body");
604 Resync_Past_Semicolon;
612 end P_Protected_Operation_Items;
614 ------------------------------
615 -- 9.5.2 Entry Declaration --
616 ------------------------------
618 -- ENTRY_DECLARATION ::=
619 -- entry DEFINING_IDENTIFIER [(DISCRETE_SUBTYPE_DEFINITION)]
620 -- PARAMETER_PROFILE;
622 -- The caller has checked that the initial token is ENTRY
624 -- Error recovery: cannot raise Error_Resync
626 function P_Entry_Declaration return Node_Id is
628 Scan_State : Saved_Scan_State;
631 Decl_Node := New_Node (N_Entry_Declaration, Token_Ptr);
634 Set_Defining_Identifier (Decl_Node, P_Defining_Identifier);
636 -- If left paren, could be (Discrete_Subtype_Definition) or Formal_Part
638 if Token = Tok_Left_Paren then
641 -- If identifier after left paren, could still be either
643 if Token = Tok_Identifier then
644 Save_Scan_State (Scan_State); -- at Id
647 -- If comma or colon after Id, must be Formal_Part
649 if Token = Tok_Comma or else Token = Tok_Colon then
650 Restore_Scan_State (Scan_State); -- to Id
651 Set_Parameter_Specifications (Decl_Node, P_Formal_Part);
653 -- Else if Id wi no comma or colon, must be discrete subtype defn
656 Restore_Scan_State (Scan_State); -- to Id
657 Set_Discrete_Subtype_Definition
658 (Decl_Node, P_Discrete_Subtype_Definition);
660 Set_Parameter_Specifications (Decl_Node, P_Parameter_Profile);
663 -- If no Id, must be discrete subtype definition
666 Set_Discrete_Subtype_Definition
667 (Decl_Node, P_Discrete_Subtype_Definition);
669 Set_Parameter_Specifications (Decl_Node, P_Parameter_Profile);
673 -- Error recovery check for illegal return
675 if Token = Tok_Return then
676 Error_Msg_SC ("entry cannot have return value!");
678 Discard_Junk_Node (P_Subtype_Indication);
681 -- Error recovery check for improper use of entry barrier in spec
683 if Token = Tok_When then
684 Error_Msg_SC ("barrier not allowed here (belongs in body)");
686 Discard_Junk_Node (P_Expression_No_Right_Paren);
691 end P_Entry_Declaration;
693 -----------------------------
694 -- 9.5.2 Accept Statement --
695 -----------------------------
697 -- ACCEPT_STATEMENT ::=
698 -- accept entry_DIRECT_NAME
699 -- [(ENTRY_INDEX)] PARAMETER_PROFILE [do
700 -- HANDLED_SEQUENCE_OF_STATEMENTS
701 -- end [entry_IDENTIFIER]];
703 -- The caller has checked that the initial token is ACCEPT
705 -- Error recovery: cannot raise Error_Resync. If an error occurs, the
706 -- scan is resynchronized past the next semicolon and control returns.
708 function P_Accept_Statement return Node_Id is
709 Scan_State : Saved_Scan_State;
710 Accept_Node : Node_Id;
715 Scope.Table (Scope.Last).Sloc := Token_Ptr;
716 Scope.Table (Scope.Last).Ecol := Start_Column;
718 Accept_Node := New_Node (N_Accept_Statement, Token_Ptr);
720 Scope.Table (Scope.Last).Labl := Token_Node;
722 Set_Entry_Direct_Name (Accept_Node, P_Identifier);
724 -- Left paren could be (Entry_Index) or Formal_Part, determine which
726 if Token = Tok_Left_Paren then
727 Save_Scan_State (Scan_State); -- at left paren
728 Scan; -- past left paren
730 -- If first token after left paren not identifier, then Entry_Index
732 if Token /= Tok_Identifier then
733 Set_Entry_Index (Accept_Node, P_Expression);
735 Set_Parameter_Specifications (Accept_Node, P_Parameter_Profile);
737 -- First token after left paren is identifier, could be either case
739 else -- Token = Tok_Identifier
740 Scan; -- past identifier
742 -- If identifier followed by comma or colon, must be Formal_Part
744 if Token = Tok_Comma or else Token = Tok_Colon then
745 Restore_Scan_State (Scan_State); -- to left paren
746 Set_Parameter_Specifications (Accept_Node, P_Parameter_Profile);
748 -- If identifier not followed by comma/colon, must be entry index
751 Restore_Scan_State (Scan_State); -- to left paren
752 Scan; -- past left paren (again!)
753 Set_Entry_Index (Accept_Node, P_Expression);
755 Set_Parameter_Specifications (Accept_Node, P_Parameter_Profile);
760 -- Scan out DO if present
762 if Token = Tok_Do then
763 Scope.Table (Scope.Last).Etyp := E_Name;
764 Scope.Table (Scope.Last).Lreq := False;
766 Hand_Seq := P_Handled_Sequence_Of_Statements;
767 Set_Handled_Statement_Sequence (Accept_Node, Hand_Seq);
768 End_Statements (Handled_Statement_Sequence (Accept_Node));
770 -- Exception handlers not allowed in Ada 95 node
772 if Present (Exception_Handlers (Hand_Seq)) then
775 ("(Ada 83) exception handlers in accept not allowed",
776 First_Non_Pragma (Exception_Handlers (Hand_Seq)));
781 Pop_Scope_Stack; -- discard unused entry
787 -- If error, resynchronize past semicolon
791 Resync_Past_Semicolon;
792 Pop_Scope_Stack; -- discard unused entry
795 end P_Accept_Statement;
797 ------------------------
798 -- 9.5.2 Entry Index --
799 ------------------------
801 -- Parsed by P_Expression (4.4)
803 -----------------------
804 -- 9.5.2 Entry Body --
805 -----------------------
808 -- entry DEFINING_IDENTIFIER ENTRY_BODY_FORMAL_PART ENTRY_BARRIER is
811 -- HANDLED_SEQUENCE_OF_STATEMENTS
812 -- end [entry_IDENTIFIER];
814 -- The caller has checked that the initial token is ENTRY
816 -- Error_Recovery: cannot raise Error_Resync
818 function P_Entry_Body return Node_Id is
819 Entry_Node : Node_Id;
820 Formal_Part_Node : Node_Id;
825 Entry_Node := New_Node (N_Entry_Body, Token_Ptr);
828 Scope.Table (Scope.Last).Ecol := Start_Column;
829 Scope.Table (Scope.Last).Lreq := False;
830 Scope.Table (Scope.Last).Etyp := E_Name;
832 Name_Node := P_Defining_Identifier;
833 Set_Defining_Identifier (Entry_Node, Name_Node);
834 Scope.Table (Scope.Last).Labl := Name_Node;
836 Formal_Part_Node := P_Entry_Body_Formal_Part;
837 Set_Entry_Body_Formal_Part (Entry_Node, Formal_Part_Node);
839 Set_Condition (Formal_Part_Node, P_Entry_Barrier);
840 Parse_Decls_Begin_End (Entry_Node);
844 -----------------------------------
845 -- 9.5.2 Entry Body Formal Part --
846 -----------------------------------
848 -- ENTRY_BODY_FORMAL_PART ::=
849 -- [(ENTRY_INDEX_SPECIFICATION)] [PARAMETER_PART]
851 -- Error_Recovery: cannot raise Error_Resync
853 function P_Entry_Body_Formal_Part return Node_Id is
854 Fpart_Node : Node_Id;
855 Scan_State : Saved_Scan_State;
858 Fpart_Node := New_Node (N_Entry_Body_Formal_Part, Token_Ptr);
860 -- See if entry index specification present, and if so parse it
862 if Token = Tok_Left_Paren then
863 Save_Scan_State (Scan_State); -- at left paren
864 Scan; -- past left paren
866 if Token = Tok_For then
867 Set_Entry_Index_Specification
868 (Fpart_Node, P_Entry_Index_Specification);
871 Restore_Scan_State (Scan_State); -- to left paren
874 -- Check for (common?) case of left paren omitted before FOR. This
875 -- is a tricky case, because the corresponding missing left paren
876 -- can cause real havoc if a formal part is present which gets
877 -- treated as part of the discrete subtype definition of the
878 -- entry index specification, so just give error and resynchronize
880 elsif Token = Tok_For then
881 T_Left_Paren; -- to give error message
885 Set_Parameter_Specifications (Fpart_Node, P_Parameter_Profile);
887 end P_Entry_Body_Formal_Part;
889 --------------------------
890 -- 9.5.2 Entry Barrier --
891 --------------------------
893 -- ENTRY_BARRIER ::= when CONDITION
895 -- Error_Recovery: cannot raise Error_Resync
897 function P_Entry_Barrier return Node_Id is
901 if Token = Tok_When then
903 Bnode := P_Expression_No_Right_Paren;
905 if Token = Tok_Colon_Equal then
906 Error_Msg_SC (""":="" should be ""=""");
908 Bnode := P_Expression_No_Right_Paren;
912 T_When; -- to give error message
920 --------------------------------------
921 -- 9.5.2 Entry Index Specification --
922 --------------------------------------
924 -- ENTRY_INDEX_SPECIFICATION ::=
925 -- for DEFINING_IDENTIFIER in DISCRETE_SUBTYPE_DEFINITION
927 -- Error recovery: can raise Error_Resync
929 function P_Entry_Index_Specification return Node_Id is
930 Iterator_Node : Node_Id;
933 Iterator_Node := New_Node (N_Entry_Index_Specification, Token_Ptr);
935 Set_Defining_Identifier (Iterator_Node, P_Defining_Identifier);
937 Set_Discrete_Subtype_Definition
938 (Iterator_Node, P_Discrete_Subtype_Definition);
939 return Iterator_Node;
940 end P_Entry_Index_Specification;
942 ---------------------------------
943 -- 9.5.3 Entry Call Statement --
944 ---------------------------------
946 -- Parsed by P_Name (4.1). Within a select, an entry call is parsed
947 -- by P_Select_Statement (9.7)
949 ------------------------------
950 -- 9.5.4 Requeue Statement --
951 ------------------------------
953 -- REQUEUE_STATEMENT ::= requeue entry_NAME [with abort];
955 -- The caller has checked that the initial token is requeue
957 -- Error recovery: can raise Error_Resync
959 function P_Requeue_Statement return Node_Id is
960 Requeue_Node : Node_Id;
963 Requeue_Node := New_Node (N_Requeue_Statement, Token_Ptr);
964 Scan; -- past REQUEUE
965 Set_Name (Requeue_Node, P_Name);
967 if Token = Tok_With then
970 Set_Abort_Present (Requeue_Node, True);
975 end P_Requeue_Statement;
977 --------------------------
978 -- 9.6 Delay Statement --
979 --------------------------
981 -- DELAY_STATEMENT ::=
982 -- DELAY_UNTIL_STATEMENT
983 -- | DELAY_RELATIVE_STATEMENT
985 -- The caller has checked that the initial token is DELAY
987 -- Error recovery: cannot raise Error_Resync
989 function P_Delay_Statement return Node_Id is
993 -- The following check for delay until misused in Ada 83 doesn't catch
994 -- all cases, but it's good enough to catch most of them!
996 if Token_Name = Name_Until then
997 Check_95_Keyword (Tok_Until, Tok_Left_Paren);
998 Check_95_Keyword (Tok_Until, Tok_Identifier);
1001 if Token = Tok_Until then
1002 return P_Delay_Until_Statement;
1004 return P_Delay_Relative_Statement;
1006 end P_Delay_Statement;
1008 --------------------------------
1009 -- 9.6 Delay Until Statement --
1010 --------------------------------
1012 -- DELAY_UNTIL_STATEMENT ::= delay until delay_EXPRESSION;
1014 -- The caller has checked that the initial token is DELAY, scanned it
1015 -- out and checked that the current token is UNTIL
1017 -- Error recovery: cannot raise Error_Resync
1019 function P_Delay_Until_Statement return Node_Id is
1020 Delay_Node : Node_Id;
1023 Delay_Node := New_Node (N_Delay_Until_Statement, Prev_Token_Ptr);
1025 Set_Expression (Delay_Node, P_Expression_No_Right_Paren);
1028 end P_Delay_Until_Statement;
1030 -----------------------------------
1031 -- 9.6 Delay Relative Statement --
1032 -----------------------------------
1034 -- DELAY_RELATIVE_STATEMENT ::= delay delay_EXPRESSION;
1036 -- The caller has checked that the initial token is DELAY, scanned it
1037 -- out and determined that the current token is not UNTIL
1039 -- Error recovery: cannot raise Error_Resync
1041 function P_Delay_Relative_Statement return Node_Id is
1042 Delay_Node : Node_Id;
1045 Delay_Node := New_Node (N_Delay_Relative_Statement, Prev_Token_Ptr);
1046 Set_Expression (Delay_Node, P_Expression_No_Right_Paren);
1047 Check_Simple_Expression_In_Ada_83 (Expression (Delay_Node));
1050 end P_Delay_Relative_Statement;
1052 ---------------------------
1053 -- 9.7 Select Statement --
1054 ---------------------------
1056 -- SELECT_STATEMENT ::=
1058 -- | TIMED_ENTRY_CALL
1059 -- | CONDITIONAL_ENTRY_CALL
1060 -- | ASYNCHRONOUS_SELECT
1062 -- SELECTIVE_ACCEPT ::=
1065 -- SELECT_ALTERNATIVE
1068 -- SELECT_ALTERNATIVE
1070 -- SEQUENCE_OF_STATEMENTS]
1073 -- GUARD ::= when CONDITION =>
1075 -- Note: the guard preceding a select alternative is included as part
1076 -- of the node generated for a selective accept alternative.
1078 -- SELECT_ALTERNATIVE ::=
1079 -- ACCEPT_ALTERNATIVE
1080 -- | DELAY_ALTERNATIVE
1081 -- | TERMINATE_ALTERNATIVE
1083 -- TIMED_ENTRY_CALL ::=
1085 -- ENTRY_CALL_ALTERNATIVE
1087 -- DELAY_ALTERNATIVE
1090 -- CONDITIONAL_ENTRY_CALL ::=
1092 -- ENTRY_CALL_ALTERNATIVE
1094 -- SEQUENCE_OF_STATEMENTS
1097 -- ENTRY_CALL_ALTERNATIVE ::=
1098 -- ENTRY_CALL_STATEMENT [SEQUENCE_OF_STATEMENTS]
1100 -- ASYNCHRONOUS_SELECT ::=
1102 -- TRIGGERING_ALTERNATIVE
1107 -- TRIGGERING_ALTERNATIVE ::=
1108 -- TRIGGERING_STATEMENT [SEQUENCE_OF_STATEMENTS]
1110 -- TRIGGERING_STATEMENT ::= ENTRY_CALL_STATEMENT | DELAY_STATEMENT
1112 -- The caller has checked that the initial token is SELECT
1114 -- Error recovery: can raise Error_Resync
1116 function P_Select_Statement return Node_Id is
1117 Select_Node : Node_Id;
1118 Select_Sloc : Source_Ptr;
1119 Stmnt_Sloc : Source_Ptr;
1120 Ecall_Node : Node_Id;
1121 Alternative : Node_Id;
1122 Select_Pragmas : List_Id;
1123 Alt_Pragmas : List_Id;
1124 Statement_List : List_Id;
1126 Cond_Expr : Node_Id;
1127 Delay_Stmnt : Node_Id;
1131 Scope.Table (Scope.Last).Etyp := E_Select;
1132 Scope.Table (Scope.Last).Ecol := Start_Column;
1133 Scope.Table (Scope.Last).Sloc := Token_Ptr;
1134 Scope.Table (Scope.Last).Labl := Error;
1136 Select_Sloc := Token_Ptr;
1137 Scan; -- past SELECT
1138 Stmnt_Sloc := Token_Ptr;
1139 Select_Pragmas := P_Pragmas_Opt;
1141 -- If first token after select is designator, then we have an entry
1142 -- call, which must be the start of a conditional entry call, timed
1143 -- entry call or asynchronous select
1145 if Token in Token_Class_Desig then
1147 -- Scan entry call statement
1150 Ecall_Node := P_Name;
1152 -- ?? The following two clauses exactly parallel code in ch5
1153 -- and should be commoned sometime
1155 if Nkind (Ecall_Node) = N_Indexed_Component then
1157 Prefix_Node : constant Node_Id := Prefix (Ecall_Node);
1158 Exprs_Node : constant List_Id := Expressions (Ecall_Node);
1161 Change_Node (Ecall_Node, N_Procedure_Call_Statement);
1162 Set_Name (Ecall_Node, Prefix_Node);
1163 Set_Parameter_Associations (Ecall_Node, Exprs_Node);
1166 elsif Nkind (Ecall_Node) = N_Function_Call then
1168 Fname_Node : constant Node_Id := Name (Ecall_Node);
1169 Params_List : constant List_Id :=
1170 Parameter_Associations (Ecall_Node);
1173 Change_Node (Ecall_Node, N_Procedure_Call_Statement);
1174 Set_Name (Ecall_Node, Fname_Node);
1175 Set_Parameter_Associations (Ecall_Node, Params_List);
1178 elsif Nkind (Ecall_Node) = N_Identifier
1179 or else Nkind (Ecall_Node) = N_Selected_Component
1181 -- Case of a call to a parameterless entry.
1184 C_Node : constant Node_Id :=
1185 New_Node (N_Procedure_Call_Statement, Stmnt_Sloc);
1187 Set_Name (C_Node, Ecall_Node);
1188 Set_Parameter_Associations (C_Node, No_List);
1189 Ecall_Node := C_Node;
1196 when Error_Resync =>
1197 Resync_Past_Semicolon;
1201 Statement_List := P_Sequence_Of_Statements (SS_Eltm_Ortm_Tatm);
1203 -- OR follows, we have a timed entry call
1205 if Token = Tok_Or then
1207 Alt_Pragmas := P_Pragmas_Opt;
1209 Select_Node := New_Node (N_Timed_Entry_Call, Select_Sloc);
1210 Set_Entry_Call_Alternative (Select_Node,
1211 Make_Entry_Call_Alternative (Stmnt_Sloc,
1212 Entry_Call_Statement => Ecall_Node,
1213 Pragmas_Before => Select_Pragmas,
1214 Statements => Statement_List));
1216 -- Only possibility is delay alternative. If we have anything
1217 -- else, give message, and treat as conditional entry call.
1219 if Token /= Tok_Delay then
1221 ("only allowed alternative in timed entry call is delay!");
1222 Discard_Junk_List (P_Sequence_Of_Statements (SS_Sreq));
1223 Set_Delay_Alternative (Select_Node, Error);
1226 Set_Delay_Alternative (Select_Node, P_Delay_Alternative);
1228 (Delay_Alternative (Select_Node), Alt_Pragmas);
1231 -- ELSE follows, we have a conditional entry call
1233 elsif Token = Tok_Else then
1235 Select_Node := New_Node (N_Conditional_Entry_Call, Select_Sloc);
1237 Set_Entry_Call_Alternative (Select_Node,
1238 Make_Entry_Call_Alternative (Stmnt_Sloc,
1239 Entry_Call_Statement => Ecall_Node,
1240 Pragmas_Before => Select_Pragmas,
1241 Statements => Statement_List));
1244 (Select_Node, P_Sequence_Of_Statements (SS_Sreq));
1246 -- Only remaining case is THEN ABORT (asynchronous select)
1248 elsif Token = Tok_Abort then
1250 Make_Asynchronous_Select (Select_Sloc,
1251 Triggering_Alternative =>
1252 Make_Triggering_Alternative (Stmnt_Sloc,
1253 Triggering_Statement => Ecall_Node,
1254 Pragmas_Before => Select_Pragmas,
1255 Statements => Statement_List),
1256 Abortable_Part => P_Abortable_Part);
1262 Error_Msg_BC ("OR or ELSE expected");
1264 Error_Msg_BC ("OR or ELSE or THEN ABORT expected");
1267 Select_Node := Error;
1272 -- Here we have a selective accept or an an asynchronous select (first
1273 -- token after SELECT is other than a designator token).
1276 -- If we have delay with no guard, could be asynchronous select
1278 if Token = Tok_Delay then
1279 Delay_Stmnt := P_Delay_Statement;
1280 Statement_List := P_Sequence_Of_Statements (SS_Eltm_Ortm_Tatm);
1282 -- Asynchronous select
1284 if Token = Tok_Abort then
1286 Make_Asynchronous_Select (Select_Sloc,
1287 Triggering_Alternative =>
1288 Make_Triggering_Alternative (Stmnt_Sloc,
1289 Triggering_Statement => Delay_Stmnt,
1290 Pragmas_Before => Select_Pragmas,
1291 Statements => Statement_List),
1292 Abortable_Part => P_Abortable_Part);
1297 -- Delay which was not an asynchronous select. Must be a selective
1298 -- accept, and since at least one accept statement is required,
1299 -- we must have at least one OR phrase present.
1302 Alt_List := New_List (
1303 Make_Delay_Alternative (Stmnt_Sloc,
1304 Delay_Statement => Delay_Stmnt,
1305 Pragmas_Before => Select_Pragmas,
1306 Statements => Statement_List));
1308 Alt_Pragmas := P_Pragmas_Opt;
1311 -- If not a delay statement, then must be another possibility for
1312 -- a selective accept alternative, or perhaps a guard is present
1315 Alt_List := New_List;
1316 Alt_Pragmas := Select_Pragmas;
1319 Select_Node := New_Node (N_Selective_Accept, Select_Sloc);
1320 Set_Select_Alternatives (Select_Node, Alt_List);
1322 -- Scan out selective accept alternatives. On entry to this loop,
1323 -- we are just past a SELECT or OR token, and any pragmas that
1324 -- immediately follow the SELECT or OR are in Alt_Pragmas.
1327 if Token = Tok_When then
1329 if Present (Alt_Pragmas) then
1330 Error_Msg_SC ("pragmas may not precede guard");
1334 Cond_Expr := P_Expression_No_Right_Paren;
1336 Alt_Pragmas := P_Pragmas_Opt;
1342 if Token = Tok_Accept then
1343 Alternative := P_Accept_Alternative;
1345 -- Check for junk attempt at asynchronous select using
1346 -- an Accept alternative as the triggering statement
1348 if Token = Tok_Abort
1349 and then Is_Empty_List (Alt_List)
1350 and then No (Cond_Expr)
1353 ("triggering statement must be entry call or delay",
1354 Sloc (Alternative));
1355 Scan; -- past junk ABORT
1356 Discard_Junk_List (P_Sequence_Of_Statements (SS_Sreq));
1361 elsif Token = Tok_Delay then
1362 Alternative := P_Delay_Alternative;
1364 elsif Token = Tok_Terminate then
1365 Alternative := P_Terminate_Alternative;
1369 ("Select alternative (ACCEPT, ABORT, DELAY) expected");
1370 Alternative := Error;
1372 if Token = Tok_Semicolon then
1373 Scan; -- past junk semicolon
1377 -- THEN ABORT at this stage is just junk
1379 if Token = Tok_Abort then
1380 Error_Msg_SP ("misplaced `THEN ABORT`");
1381 Scan; -- past junk ABORT
1382 Discard_Junk_List (P_Sequence_Of_Statements (SS_Sreq));
1387 if Alternative /= Error then
1388 Set_Condition (Alternative, Cond_Expr);
1389 Set_Pragmas_Before (Alternative, Alt_Pragmas);
1390 Append (Alternative, Alt_List);
1393 exit when Token /= Tok_Or;
1397 Alt_Pragmas := P_Pragmas_Opt;
1400 if Token = Tok_Else then
1403 (Select_Node, P_Sequence_Of_Statements (SS_Ortm_Sreq));
1405 if Token = Tok_Or then
1406 Error_Msg_SC ("select alternative cannot follow else part!");
1414 end P_Select_Statement;
1416 -----------------------------
1417 -- 9.7.1 Selective Accept --
1418 -----------------------------
1420 -- Parsed by P_Select_Statement (9.7)
1426 -- Parsed by P_Select_Statement (9.7)
1428 -------------------------------
1429 -- 9.7.1 Select Alternative --
1430 -------------------------------
1432 -- SELECT_ALTERNATIVE ::=
1433 -- ACCEPT_ALTERNATIVE
1434 -- | DELAY_ALTERNATIVE
1435 -- | TERMINATE_ALTERNATIVE
1437 -- Note: the guard preceding a select alternative is included as part
1438 -- of the node generated for a selective accept alternative.
1440 -- Error recovery: cannot raise Error_Resync
1442 -------------------------------
1443 -- 9.7.1 Accept Alternative --
1444 -------------------------------
1446 -- ACCEPT_ALTERNATIVE ::=
1447 -- ACCEPT_STATEMENT [SEQUENCE_OF_STATEMENTS]
1449 -- Error_Recovery: Cannot raise Error_Resync
1451 -- Note: the caller is responsible for setting the Pragmas_Before
1452 -- field of the returned N_Terminate_Alternative node.
1454 function P_Accept_Alternative return Node_Id is
1455 Accept_Alt_Node : Node_Id;
1458 Accept_Alt_Node := New_Node (N_Accept_Alternative, Token_Ptr);
1459 Set_Accept_Statement (Accept_Alt_Node, P_Accept_Statement);
1461 -- Note: the reason that we accept THEN ABORT as a terminator for
1462 -- the sequence of statements is for error recovery which allows
1463 -- for misuse of an accept statement as a triggering statememt.
1466 (Accept_Alt_Node, P_Sequence_Of_Statements (SS_Eltm_Ortm_Tatm));
1467 return Accept_Alt_Node;
1468 end P_Accept_Alternative;
1470 ------------------------------
1471 -- 9.7.1 Delay Alternative --
1472 ------------------------------
1474 -- DELAY_ALTERNATIVE ::=
1475 -- DELAY_STATEMENT [SEQUENCE_OF_STATEMENTS]
1477 -- Error_Recovery: Cannot raise Error_Resync
1479 -- Note: the caller is responsible for setting the Pragmas_Before
1480 -- field of the returned N_Terminate_Alternative node.
1482 function P_Delay_Alternative return Node_Id is
1483 Delay_Alt_Node : Node_Id;
1486 Delay_Alt_Node := New_Node (N_Delay_Alternative, Token_Ptr);
1487 Set_Delay_Statement (Delay_Alt_Node, P_Delay_Statement);
1489 -- Note: the reason that we accept THEN ABORT as a terminator for
1490 -- the sequence of statements is for error recovery which allows
1491 -- for misuse of an accept statement as a triggering statememt.
1494 (Delay_Alt_Node, P_Sequence_Of_Statements (SS_Eltm_Ortm_Tatm));
1495 return Delay_Alt_Node;
1496 end P_Delay_Alternative;
1498 ----------------------------------
1499 -- 9.7.1 Terminate Alternative --
1500 ----------------------------------
1502 -- TERMINATE_ALTERNATIVE ::= terminate;
1504 -- Error_Recovery: Cannot raise Error_Resync
1506 -- Note: the caller is responsible for setting the Pragmas_Before
1507 -- field of the returned N_Terminate_Alternative node.
1509 function P_Terminate_Alternative return Node_Id is
1510 Terminate_Alt_Node : Node_Id;
1513 Terminate_Alt_Node := New_Node (N_Terminate_Alternative, Token_Ptr);
1514 Scan; -- past TERMINATE
1517 -- For all other select alternatives, the sequence of statements
1518 -- after the alternative statement will swallow up any pragmas
1519 -- coming in this position. But the terminate alternative has no
1520 -- sequence of statements, so the pragmas here must be treated
1523 Set_Pragmas_After (Terminate_Alt_Node, P_Pragmas_Opt);
1524 return Terminate_Alt_Node;
1525 end P_Terminate_Alternative;
1527 -----------------------------
1528 -- 9.7.2 Timed Entry Call --
1529 -----------------------------
1531 -- Parsed by P_Select_Statement (9.7)
1533 -----------------------------------
1534 -- 9.7.2 Entry Call Alternative --
1535 -----------------------------------
1537 -- Parsed by P_Select_Statement (9.7)
1539 -----------------------------------
1540 -- 9.7.3 Conditional Entry Call --
1541 -----------------------------------
1543 -- Parsed by P_Select_Statement (9.7)
1545 --------------------------------
1546 -- 9.7.4 Asynchronous Select --
1547 --------------------------------
1549 -- Parsed by P_Select_Statement (9.7)
1551 -----------------------------------
1552 -- 9.7.4 Triggering Alternative --
1553 -----------------------------------
1555 -- Parsed by P_Select_Statement (9.7)
1557 ---------------------------------
1558 -- 9.7.4 Triggering Statement --
1559 ---------------------------------
1561 -- Parsed by P_Select_Statement (9.7)
1563 ---------------------------
1564 -- 9.7.4 Abortable Part --
1565 ---------------------------
1567 -- ABORTABLE_PART ::= SEQUENCE_OF_STATEMENTS
1569 -- The caller has verified that THEN ABORT is present, and Token is
1570 -- pointing to the ABORT on entry (or if not, then we have an error)
1572 -- Error recovery: cannot raise Error_Resync
1574 function P_Abortable_Part return Node_Id is
1575 Abortable_Part_Node : Node_Id;
1578 Abortable_Part_Node := New_Node (N_Abortable_Part, Token_Ptr);
1579 T_Abort; -- scan past ABORT
1582 Error_Msg_SP ("(Ada 83) asynchronous select not allowed!");
1585 Set_Statements (Abortable_Part_Node, P_Sequence_Of_Statements (SS_Sreq));
1586 return Abortable_Part_Node;
1587 end P_Abortable_Part;
1589 --------------------------
1590 -- 9.8 Abort Statement --
1591 --------------------------
1593 -- ABORT_STATEMENT ::= abort task_NAME {, task_NAME};
1595 -- The caller has checked that the initial token is ABORT
1597 -- Error recovery: cannot raise Error_Resync
1599 function P_Abort_Statement return Node_Id is
1600 Abort_Node : Node_Id;
1603 Abort_Node := New_Node (N_Abort_Statement, Token_Ptr);
1605 Set_Names (Abort_Node, New_List);
1608 Append (P_Name, Names (Abort_Node));
1609 exit when Token /= Tok_Comma;
1615 end P_Abort_Statement;