Add an UNSPEC_PROLOGUE_USE to prevent the link register from being considered dead.
[official-gcc.git] / gcc / ada / par-ch5.adb
blob3d3341546f43971f14f414543acd22bb97a8aea4
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- P A R . C H 5 --
6 -- --
7 -- B o d y --
8 -- --
9 -- --
10 -- Copyright (C) 1992-2001, Free Software Foundation, Inc. --
11 -- --
12 -- GNAT is free software; you can redistribute it and/or modify it under --
13 -- terms of the GNU General Public License as published by the Free Soft- --
14 -- ware Foundation; either version 2, or (at your option) any later ver- --
15 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
18 -- for more details. You should have received a copy of the GNU General --
19 -- Public License distributed with GNAT; see file COPYING. If not, write --
20 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
21 -- MA 02111-1307, USA. --
22 -- --
23 -- GNAT was originally developed by the GNAT team at New York University. --
24 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 -- --
26 ------------------------------------------------------------------------------
28 pragma Style_Checks (All_Checks);
29 -- Turn off subprogram body ordering check. Subprograms are in order
30 -- by RM section rather than alphabetical
32 separate (Par)
33 package body Ch5 is
35 -- Local functions, used only in this chapter
37 function P_Case_Statement return Node_Id;
38 function P_Case_Statement_Alternative return Node_Id;
39 function P_Condition return Node_Id;
40 function P_Exit_Statement return Node_Id;
41 function P_Goto_Statement return Node_Id;
42 function P_If_Statement return Node_Id;
43 function P_Label return Node_Id;
44 function P_Loop_Parameter_Specification return Node_Id;
45 function P_Null_Statement return Node_Id;
47 function P_Assignment_Statement (LHS : Node_Id) return Node_Id;
48 -- Parse assignment statement. On entry, the caller has scanned the left
49 -- hand side (passed in as Lhs), and the colon-equal (or some symbol
50 -- taken to be an error equivalent such as equal).
52 function P_Begin_Statement (Block_Name : Node_Id := Empty) return Node_Id;
53 -- Parse begin-end statement. If Block_Name is non-Empty on entry, it is
54 -- the N_Identifier node for the label on the block. If Block_Name is
55 -- Empty on entry (the default), then the block statement is unlabeled.
57 function P_Declare_Statement (Block_Name : Node_Id := Empty) return Node_Id;
58 -- Parse declare block. If Block_Name is non-Empty on entry, it is
59 -- the N_Identifier node for the label on the block. If Block_Name is
60 -- Empty on entry (the default), then the block statement is unlabeled.
62 function P_For_Statement (Loop_Name : Node_Id := Empty) return Node_Id;
63 -- Parse for statement. If Loop_Name is non-Empty on entry, it is
64 -- the N_Identifier node for the label on the loop. If Loop_Name is
65 -- Empty on entry (the default), then the for statement is unlabeled.
67 function P_Loop_Statement (Loop_Name : Node_Id := Empty) return Node_Id;
68 -- Parse loop statement. If Loop_Name is non-Empty on entry, it is
69 -- the N_Identifier node for the label on the loop. If Loop_Name is
70 -- Empty on entry (the default), then the loop statement is unlabeled.
72 function P_While_Statement (Loop_Name : Node_Id := Empty) return Node_Id;
73 -- Parse while statement. If Loop_Name is non-Empty on entry, it is
74 -- the N_Identifier node for the label on the loop. If Loop_Name is
75 -- Empty on entry (the default), then the while statement is unlabeled.
77 function Set_Loop_Block_Name (L : Character) return Name_Id;
78 -- Given a letter 'L' for a loop or 'B' for a block, returns a name
79 -- of the form L_nn or B_nn where nn is a serial number obtained by
80 -- incrementing the variable Loop_Block_Count.
82 procedure Then_Scan;
83 -- Scan past THEN token, testing for illegal junk after it
85 ---------------------------------
86 -- 5.1 Sequence of Statements --
87 ---------------------------------
89 -- SEQUENCE_OF_STATEMENTS ::= STATEMENT {STATEMENT}
91 -- STATEMENT ::=
92 -- {LABEL} SIMPLE_STATEMENT | {LABEL} COMPOUND_STATEMENT
94 -- SIMPLE_STATEMENT ::= NULL_STATEMENT
95 -- | ASSIGNMENT_STATEMENT | EXIT_STATEMENT
96 -- | GOTO_STATEMENT | PROCEDURE_CALL_STATEMENT
97 -- | RETURN_STATEMENT | ENTRY_CALL_STATEMENT
98 -- | REQUEUE_STATEMENT | DELAY_STATEMENT
99 -- | ABORT_STATEMENT | RAISE_STATEMENT
100 -- | CODE_STATEMENT
102 -- COMPOUND_STATEMENT ::=
103 -- IF_STATEMENT | CASE_STATEMENT
104 -- | LOOP_STATEMENT | BLOCK_STATEMENT
105 -- | ACCEPT_STATEMENT | SELECT_STATEMENT
107 -- This procedure scans a sequence of statements. The caller sets SS_Flags
108 -- to indicate acceptable termination conditions for the sequence:
110 -- SS_Flags.Eftm Terminate on ELSIF
111 -- SS_Flags.Eltm Terminate on ELSE
112 -- SS_Flags.Extm Terminate on EXCEPTION
113 -- SS_Flags.Ortm Terminate on OR
114 -- SS_Flags.Tatm Terminate on THEN ABORT (Token = ABORT on return)
115 -- SS_Flags.Whtm Terminate on WHEN
116 -- SS_Flags.Unco Unconditional terminate after scanning one statement
118 -- In addition, the scan is always terminated by encountering END or the
119 -- end of file (EOF) condition. If one of the six above terminators is
120 -- encountered with the corresponding SS_Flags flag not set, then the
121 -- action taken is as follows:
123 -- If the keyword occurs to the left of the expected column of the end
124 -- for the current sequence (as recorded in the current end context),
125 -- then it is assumed to belong to an outer context, and is considered
126 -- to terminate the sequence of statements.
128 -- If the keyword occurs to the right of, or in the expected column of
129 -- the end for the current sequence, then an error message is output,
130 -- the keyword together with its associated context is skipped, and
131 -- the statement scan continues until another terminator is found.
133 -- Note that the first action means that control can return to the caller
134 -- with Token set to a terminator other than one of those specified by the
135 -- SS parameter. The caller should treat such a case as equivalent to END.
137 -- In addition, the flag SS_Flags.Sreq is set to True to indicate that at
138 -- least one real statement (other than a pragma) is required in the
139 -- statement sequence. During the processing of the sequence, this
140 -- flag is manipulated to indicate the current status of the requirement
141 -- for a statement. For example, it is turned off by the occurrence of a
142 -- statement, and back on by a label (which requires a following statement)
144 -- Error recovery: cannot raise Error_Resync. If an error occurs during
145 -- parsing a statement, then the scan pointer is advanced past the next
146 -- semicolon and the parse continues.
148 function P_Sequence_Of_Statements (SS_Flags : SS_Rec) return List_Id is
150 Statement_Required : Boolean;
151 -- This flag indicates if a subsequent statement (other than a pragma)
152 -- is required. It is initialized from the Sreq flag, and modified as
153 -- statements are scanned (a statement turns it off, and a label turns
154 -- it back on again since a statement must follow a label).
156 Declaration_Found : Boolean := False;
157 -- This flag is set True if a declaration is encountered, so that the
158 -- error message about declarations in the statement part is only
159 -- given once for a given sequence of statements.
161 Scan_State_Label : Saved_Scan_State;
162 Scan_State : Saved_Scan_State;
164 Statement_List : List_Id;
165 Block_Label : Name_Id;
166 Id_Node : Node_Id;
167 Name_Node : Node_Id;
169 procedure Junk_Declaration;
170 -- Procedure called to handle error of declaration encountered in
171 -- statement sequence.
173 procedure Test_Statement_Required;
174 -- Flag error if Statement_Required flag set
176 procedure Junk_Declaration is
177 begin
178 if (not Declaration_Found) or All_Errors_Mode then
179 Error_Msg_SC ("declarations must come before BEGIN");
180 Declaration_Found := True;
181 end if;
183 Skip_Declaration (Statement_List);
184 end Junk_Declaration;
186 procedure Test_Statement_Required is
187 begin
188 if Statement_Required then
189 Error_Msg_BC ("statement expected");
190 end if;
191 end Test_Statement_Required;
193 -- Start of processing for P_Sequence_Of_Statements
195 begin
196 Statement_List := New_List;
197 Statement_Required := SS_Flags.Sreq;
199 loop
200 while Token = Tok_Semicolon loop
201 Error_Msg_SC ("unexpected semicolon ignored");
202 Scan; -- past junk semicolon
203 end loop;
205 begin
206 if Style_Check then Style.Check_Indentation; end if;
208 -- Deal with reserved identifier (in assignment or call)
210 if Is_Reserved_Identifier then
211 Save_Scan_State (Scan_State); -- at possible bad identifier
212 Scan; -- and scan past it
214 -- We have an reserved word which is spelled in identifier
215 -- style, so the question is whether it really is intended
216 -- to be an identifier.
219 -- If followed by a semicolon, then it is an identifier,
220 -- with the exception of the cases tested for below.
222 (Token = Tok_Semicolon
223 and then Prev_Token /= Tok_Return
224 and then Prev_Token /= Tok_Null
225 and then Prev_Token /= Tok_Raise
226 and then Prev_Token /= Tok_End
227 and then Prev_Token /= Tok_Exit)
229 -- If followed by colon, colon-equal, or dot, then we
230 -- definitely have an identifier (could not be reserved)
232 or else Token = Tok_Colon
233 or else Token = Tok_Colon_Equal
234 or else Token = Tok_Dot
236 -- Left paren means we have an identifier except for those
237 -- reserved words that can legitimately be followed by a
238 -- left paren.
240 or else
241 (Token = Tok_Left_Paren
242 and then Prev_Token /= Tok_Case
243 and then Prev_Token /= Tok_Delay
244 and then Prev_Token /= Tok_If
245 and then Prev_Token /= Tok_Elsif
246 and then Prev_Token /= Tok_Return
247 and then Prev_Token /= Tok_When
248 and then Prev_Token /= Tok_While
249 and then Prev_Token /= Tok_Separate)
250 then
251 -- Here we have an apparent reserved identifier and the
252 -- token past it is appropriate to this usage (and would
253 -- be a definite error if this is not an identifier). What
254 -- we do is to use P_Identifier to fix up the identifier,
255 -- and then fall into the normal processing.
257 Restore_Scan_State (Scan_State); -- back to the ID
258 Scan_Reserved_Identifier (Force_Msg => False);
260 -- Not a reserved identifier after all (or at least we can't
261 -- be sure that it is), so reset the scan and continue.
263 else
264 Restore_Scan_State (Scan_State); -- back to the reserved word
265 end if;
266 end if;
268 -- Now look to see what kind of statement we have
270 case Token is
272 -- Case of end or EOF
274 when Tok_End | Tok_EOF =>
276 -- These tokens always terminate the statement sequence
278 Test_Statement_Required;
279 exit;
281 -- Case of ELSIF
283 when Tok_Elsif =>
285 -- Terminate if Eftm set or if the ELSIF is to the left
286 -- of the expected column of the end for this sequence
288 if SS_Flags.Eftm
289 or else Start_Column < Scope.Table (Scope.Last).Ecol
290 then
291 Test_Statement_Required;
292 exit;
294 -- Otherwise complain and skip past ELSIF Condition then
296 else
297 Error_Msg_SC ("ELSIF not allowed here");
298 Scan; -- past ELSIF
299 Discard_Junk_Node (P_Expression_No_Right_Paren);
300 Then_Scan;
301 Statement_Required := False;
302 end if;
304 -- Case of ELSE
306 when Tok_Else =>
308 -- Terminate if Eltm set or if the else is to the left
309 -- of the expected column of the end for this sequence
311 if SS_Flags.Eltm
312 or else Start_Column < Scope.Table (Scope.Last).Ecol
313 then
314 Test_Statement_Required;
315 exit;
317 -- Otherwise complain and skip past else
319 else
320 Error_Msg_SC ("ELSE not allowed here");
321 Scan; -- past ELSE
322 Statement_Required := False;
323 end if;
325 -- Case of exception
327 when Tok_Exception =>
328 Test_Statement_Required;
330 -- If Extm not set and the exception is not to the left
331 -- of the expected column of the end for this sequence, then
332 -- we assume it belongs to the current sequence, even though
333 -- it is not permitted.
335 if not SS_Flags.Extm and then
336 Start_Column >= Scope.Table (Scope.Last).Ecol
338 then
339 Error_Msg_SC ("exception handler not permitted here");
340 Scan; -- past EXCEPTION
341 Discard_Junk_List (Parse_Exception_Handlers);
342 end if;
344 -- Always return, in the case where we scanned out handlers
345 -- that we did not expect, Parse_Exception_Handlers returned
346 -- with Token being either end or EOF, so we are OK
348 exit;
350 -- Case of OR
352 when Tok_Or =>
354 -- Terminate if Ortm set or if the or is to the left
355 -- of the expected column of the end for this sequence
357 if SS_Flags.Ortm
358 or else Start_Column < Scope.Table (Scope.Last).Ecol
359 then
360 Test_Statement_Required;
361 exit;
363 -- Otherwise complain and skip past or
365 else
366 Error_Msg_SC ("OR not allowed here");
367 Scan; -- past or
368 Statement_Required := False;
369 end if;
371 -- Case of THEN (deal also with THEN ABORT)
373 when Tok_Then =>
374 Save_Scan_State (Scan_State); -- at THEN
375 Scan; -- past THEN
377 -- Terminate if THEN ABORT allowed (ATC case)
379 exit when SS_Flags.Tatm and then Token = Tok_Abort;
381 -- Otherwise we treat THEN as some kind of mess where we
382 -- did not see the associated IF, but we pick up assuming
383 -- it had been there!
385 Restore_Scan_State (Scan_State); -- to THEN
386 Append_To (Statement_List, P_If_Statement);
387 Statement_Required := False;
389 -- Case of WHEN (error because we are not in a case)
391 when Tok_When | Tok_Others =>
393 -- Terminate if Whtm set or if the WHEN is to the left
394 -- of the expected column of the end for this sequence
396 if SS_Flags.Whtm
397 or else Start_Column < Scope.Table (Scope.Last).Ecol
398 then
399 Test_Statement_Required;
400 exit;
402 -- Otherwise complain and skip when Choice {| Choice} =>
404 else
405 Error_Msg_SC ("WHEN not allowed here");
406 Scan; -- past when
407 Discard_Junk_List (P_Discrete_Choice_List);
408 TF_Arrow;
409 Statement_Required := False;
410 end if;
412 -- Cases of statements starting with an identifier
414 when Tok_Identifier =>
415 Check_Bad_Layout;
417 -- Save scan pointers and line number in case block label
419 Id_Node := Token_Node;
420 Block_Label := Token_Name;
421 Save_Scan_State (Scan_State_Label); -- at possible label
422 Scan; -- past Id
424 -- Check for common case of assignment, since it occurs
425 -- frequently, and we want to process it efficiently.
427 if Token = Tok_Colon_Equal then
428 Scan; -- past the colon-equal
429 Append_To (Statement_List,
430 P_Assignment_Statement (Id_Node));
431 Statement_Required := False;
433 -- Check common case of procedure call, another case that
434 -- we want to speed up as much as possible.
436 elsif Token = Tok_Semicolon then
437 Append_To (Statement_List,
438 P_Statement_Name (Id_Node));
439 Scan; -- past semicolon
440 Statement_Required := False;
442 -- Check for case of "go to" in place of "goto"
444 elsif Token = Tok_Identifier
445 and then Block_Label = Name_Go
446 and then Token_Name = Name_To
447 then
448 Error_Msg_SP ("goto is one word");
449 Append_To (Statement_List, P_Goto_Statement);
450 Statement_Required := False;
452 -- Check common case of = used instead of :=, just so we
453 -- give a better error message for this special misuse.
455 elsif Token = Tok_Equal then
456 T_Colon_Equal; -- give := expected message
457 Append_To (Statement_List,
458 P_Assignment_Statement (Id_Node));
459 Statement_Required := False;
461 -- Check case of loop label or block label
463 elsif Token = Tok_Colon
464 or else (Token in Token_Class_Labeled_Stmt
465 and then not Token_Is_At_Start_Of_Line)
466 then
467 T_Colon; -- past colon (if there, or msg for missing one)
469 -- Test for more than one label
471 loop
472 exit when Token /= Tok_Identifier;
473 Save_Scan_State (Scan_State); -- at second Id
474 Scan; -- past Id
476 if Token = Tok_Colon then
477 Error_Msg_SP
478 ("only one label allowed on block or loop");
479 Scan; -- past colon on extra label
481 -- Use the second label as the "real" label
483 Scan_State_Label := Scan_State;
485 -- We will set Error_name as the Block_Label since
486 -- we really don't know which of the labels might
487 -- be used at the end of the loop or block!
489 Block_Label := Error_Name;
491 -- If Id with no colon, then backup to point to the
492 -- Id and we will issue the message below when we try
493 -- to scan out the statement as some other form.
495 else
496 Restore_Scan_State (Scan_State); -- to second Id
497 exit;
498 end if;
499 end loop;
501 -- Loop_Statement (labeled Loop_Statement)
503 if Token = Tok_Loop then
504 Append_To (Statement_List,
505 P_Loop_Statement (Id_Node));
507 -- While statement (labeled loop statement with WHILE)
509 elsif Token = Tok_While then
510 Append_To (Statement_List,
511 P_While_Statement (Id_Node));
513 -- Declare statement (labeled block statement with
514 -- DECLARE part)
516 elsif Token = Tok_Declare then
517 Append_To (Statement_List,
518 P_Declare_Statement (Id_Node));
520 -- Begin statement (labeled block statement with no
521 -- DECLARE part)
523 elsif Token = Tok_Begin then
524 Append_To (Statement_List,
525 P_Begin_Statement (Id_Node));
527 -- For statement (labeled loop statement with FOR)
529 elsif Token = Tok_For then
530 Append_To (Statement_List,
531 P_For_Statement (Id_Node));
533 -- Improper statement follows label. If we have an
534 -- expression token, then assume the colon was part
535 -- of a misplaced declaration.
537 elsif Token not in Token_Class_Eterm then
538 Restore_Scan_State (Scan_State_Label);
539 Junk_Declaration;
541 -- Otherwise complain we have inappropriate statement
543 else
544 Error_Msg_AP
545 ("loop or block statement must follow label");
546 end if;
548 Statement_Required := False;
550 -- Here we have an identifier followed by something
551 -- other than a colon, semicolon or assignment symbol.
552 -- The only valid possibility is a name extension symbol
554 elsif Token in Token_Class_Namext then
555 Restore_Scan_State (Scan_State_Label); -- to Id
556 Name_Node := P_Name;
558 -- Skip junk right parens in this context
560 while Token = Tok_Right_Paren loop
561 Error_Msg_SC ("extra right paren");
562 Scan; -- past )
563 end loop;
565 -- Check context following call
567 if Token = Tok_Colon_Equal then
568 Scan; -- past colon equal
569 Append_To (Statement_List,
570 P_Assignment_Statement (Name_Node));
571 Statement_Required := False;
573 -- Check common case of = used instead of :=
575 elsif Token = Tok_Equal then
576 T_Colon_Equal; -- give := expected message
577 Append_To (Statement_List,
578 P_Assignment_Statement (Name_Node));
579 Statement_Required := False;
581 -- Check apostrophe cases
583 elsif Token = Tok_Apostrophe then
584 Append_To (Statement_List,
585 P_Code_Statement (Name_Node));
586 Statement_Required := False;
588 -- The only other valid item after a name is ; which
589 -- means that the item we just scanned was a call.
591 elsif Token = Tok_Semicolon then
592 Append_To (Statement_List,
593 P_Statement_Name (Name_Node));
594 Scan; -- past semicolon
595 Statement_Required := False;
597 -- A slash following an identifier or a selected
598 -- component in this situation is most likely a
599 -- period (have a look at the keyboard :-)
601 elsif Token = Tok_Slash
602 and then (Nkind (Name_Node) = N_Identifier
603 or else
604 Nkind (Name_Node) = N_Selected_Component)
605 then
606 Error_Msg_SC ("""/"" should be "".""");
607 Statement_Required := False;
608 raise Error_Resync;
610 -- Else we have a missing semicolon
612 else
613 TF_Semicolon;
614 Statement_Required := False;
615 end if;
617 -- If junk after identifier, check if identifier is an
618 -- instance of an incorrectly spelled keyword. If so, we
619 -- do nothing. The Bad_Spelling_Of will have reset Token
620 -- to the appropriate keyword, so the next time round the
621 -- loop we will process the modified token. Note that we
622 -- check for ELSIF before ELSE here. That's not accidental.
623 -- We don't want to identify a misspelling of ELSE as
624 -- ELSIF, and in particular we do not want to treat ELSEIF
625 -- as ELSE IF.
627 else
628 Restore_Scan_State (Scan_State_Label); -- to identifier
630 if Bad_Spelling_Of (Tok_Abort)
631 or else Bad_Spelling_Of (Tok_Accept)
632 or else Bad_Spelling_Of (Tok_Case)
633 or else Bad_Spelling_Of (Tok_Declare)
634 or else Bad_Spelling_Of (Tok_Delay)
635 or else Bad_Spelling_Of (Tok_Elsif)
636 or else Bad_Spelling_Of (Tok_Else)
637 or else Bad_Spelling_Of (Tok_End)
638 or else Bad_Spelling_Of (Tok_Exception)
639 or else Bad_Spelling_Of (Tok_Exit)
640 or else Bad_Spelling_Of (Tok_For)
641 or else Bad_Spelling_Of (Tok_Goto)
642 or else Bad_Spelling_Of (Tok_If)
643 or else Bad_Spelling_Of (Tok_Loop)
644 or else Bad_Spelling_Of (Tok_Or)
645 or else Bad_Spelling_Of (Tok_Pragma)
646 or else Bad_Spelling_Of (Tok_Raise)
647 or else Bad_Spelling_Of (Tok_Requeue)
648 or else Bad_Spelling_Of (Tok_Return)
649 or else Bad_Spelling_Of (Tok_Select)
650 or else Bad_Spelling_Of (Tok_When)
651 or else Bad_Spelling_Of (Tok_While)
652 then
653 null;
655 -- If not a bad spelling, then we really have junk
657 else
658 Scan; -- past identifier again
660 -- If next token is first token on line, then we
661 -- consider that we were missing a semicolon after
662 -- the identifier, and process it as a procedure
663 -- call with no parameters.
665 if Token_Is_At_Start_Of_Line then
666 Append_To (Statement_List,
667 P_Statement_Name (Id_Node));
668 T_Semicolon; -- to give error message
669 Statement_Required := False;
671 -- Otherwise we give a missing := message and
672 -- simply abandon the junk that is there now.
674 else
675 T_Colon_Equal; -- give := expected message
676 raise Error_Resync;
677 end if;
679 end if;
680 end if;
682 -- Statement starting with operator symbol. This could be
683 -- a call, a name starting an assignment, or a qualified
684 -- expression.
686 when Tok_Operator_Symbol =>
687 Check_Bad_Layout;
688 Name_Node := P_Name;
690 -- An attempt at a range attribute or a qualified expression
691 -- must be illegal here (a code statement cannot possibly
692 -- allow qualification by a function name).
694 if Token = Tok_Apostrophe then
695 Error_Msg_SC ("apostrophe illegal here");
696 raise Error_Resync;
697 end if;
699 -- Scan possible assignment if we have a name
701 if Expr_Form = EF_Name
702 and then Token = Tok_Colon_Equal
703 then
704 Scan; -- past colon equal
705 Append_To (Statement_List,
706 P_Assignment_Statement (Name_Node));
707 else
708 Append_To (Statement_List,
709 P_Statement_Name (Name_Node));
710 end if;
712 TF_Semicolon;
713 Statement_Required := False;
715 -- Label starting with << which must precede real statement
717 when Tok_Less_Less =>
718 Append_To (Statement_List, P_Label);
719 Statement_Required := True;
721 -- Pragma appearing as a statement in a statement sequence
723 when Tok_Pragma =>
724 Check_Bad_Layout;
725 Append_To (Statement_List, P_Pragma);
727 -- Abort_Statement
729 when Tok_Abort =>
730 Check_Bad_Layout;
731 Append_To (Statement_List, P_Abort_Statement);
732 Statement_Required := False;
734 -- Accept_Statement
736 when Tok_Accept =>
737 Check_Bad_Layout;
738 Append_To (Statement_List, P_Accept_Statement);
739 Statement_Required := False;
741 -- Begin_Statement (Block_Statement with no declare, no label)
743 when Tok_Begin =>
744 Check_Bad_Layout;
745 Append_To (Statement_List, P_Begin_Statement);
746 Statement_Required := False;
748 -- Case_Statement
750 when Tok_Case =>
751 Check_Bad_Layout;
752 Append_To (Statement_List, P_Case_Statement);
753 Statement_Required := False;
755 -- Block_Statement with DECLARE and no label
757 when Tok_Declare =>
758 Check_Bad_Layout;
759 Append_To (Statement_List, P_Declare_Statement);
760 Statement_Required := False;
762 -- Delay_Statement
764 when Tok_Delay =>
765 Check_Bad_Layout;
766 Append_To (Statement_List, P_Delay_Statement);
767 Statement_Required := False;
769 -- Exit_Statement
771 when Tok_Exit =>
772 Check_Bad_Layout;
773 Append_To (Statement_List, P_Exit_Statement);
774 Statement_Required := False;
776 -- Loop_Statement with FOR and no label
778 when Tok_For =>
779 Check_Bad_Layout;
780 Append_To (Statement_List, P_For_Statement);
781 Statement_Required := False;
783 -- Goto_Statement
785 when Tok_Goto =>
786 Check_Bad_Layout;
787 Append_To (Statement_List, P_Goto_Statement);
788 Statement_Required := False;
790 -- If_Statement
792 when Tok_If =>
793 Check_Bad_Layout;
794 Append_To (Statement_List, P_If_Statement);
795 Statement_Required := False;
797 -- Loop_Statement
799 when Tok_Loop =>
800 Check_Bad_Layout;
801 Append_To (Statement_List, P_Loop_Statement);
802 Statement_Required := False;
804 -- Null_Statement
806 when Tok_Null =>
807 Check_Bad_Layout;
808 Append_To (Statement_List, P_Null_Statement);
809 Statement_Required := False;
811 -- Raise_Statement
813 when Tok_Raise =>
814 Check_Bad_Layout;
815 Append_To (Statement_List, P_Raise_Statement);
816 Statement_Required := False;
818 -- Requeue_Statement
820 when Tok_Requeue =>
821 Check_Bad_Layout;
822 Append_To (Statement_List, P_Requeue_Statement);
823 Statement_Required := False;
825 -- Return_Statement
827 when Tok_Return =>
828 Check_Bad_Layout;
829 Append_To (Statement_List, P_Return_Statement);
830 Statement_Required := False;
832 -- Select_Statement
834 when Tok_Select =>
835 Check_Bad_Layout;
836 Append_To (Statement_List, P_Select_Statement);
837 Statement_Required := False;
839 -- While_Statement (Block_Statement with while and no loop)
841 when Tok_While =>
842 Check_Bad_Layout;
843 Append_To (Statement_List, P_While_Statement);
844 Statement_Required := False;
846 -- Anything else is some kind of junk, signal an error message
847 -- and then raise Error_Resync, to merge with the normal
848 -- handling of a bad statement.
850 when others =>
852 if Token in Token_Class_Declk then
853 Junk_Declaration;
855 else
856 Error_Msg_BC ("statement expected");
857 raise Error_Resync;
858 end if;
859 end case;
861 -- On error resynchronization, skip past next semicolon, and, since
862 -- we are still in the statement loop, look for next statement. We
863 -- set Statement_Required False to avoid an unnecessary error message
864 -- complaining that no statement was found (i.e. we consider the
865 -- junk to satisfy the requirement for a statement being present).
867 exception
868 when Error_Resync =>
869 Resync_Past_Semicolon_Or_To_Loop_Or_Then;
870 Statement_Required := False;
871 end;
873 exit when SS_Flags.Unco;
875 end loop;
877 return Statement_List;
879 end P_Sequence_Of_Statements;
881 --------------------
882 -- 5.1 Statement --
883 --------------------
885 -- Parsed by P_Sequence_Of_Statements (5.1), except for the case
886 -- of a statement of the form of a name, which is handled here. The
887 -- argument passed in is the tree for the name which has been scanned
888 -- The returned value is the corresponding statement form.
890 -- This routine is also used by Par.Prag for processing the procedure
891 -- call that appears as the second argument of a pragma Assert.
893 -- Error recovery: cannot raise Error_Resync
895 function P_Statement_Name (Name_Node : Node_Id) return Node_Id is
896 Stmt_Node : Node_Id;
898 begin
899 -- Case of Indexed component, which is a procedure call with arguments
901 if Nkind (Name_Node) = N_Indexed_Component then
902 declare
903 Prefix_Node : Node_Id := Prefix (Name_Node);
904 Exprs_Node : List_Id := Expressions (Name_Node);
905 begin
906 Change_Node (Name_Node, N_Procedure_Call_Statement);
907 Set_Name (Name_Node, Prefix_Node);
908 Set_Parameter_Associations (Name_Node, Exprs_Node);
909 return Name_Node;
910 end;
912 -- Case of function call node, which is a really a procedure call
914 elsif Nkind (Name_Node) = N_Function_Call then
915 declare
916 Fname_Node : Node_Id := Name (Name_Node);
917 Params_List : List_Id := Parameter_Associations (Name_Node);
919 begin
920 Change_Node (Name_Node, N_Procedure_Call_Statement);
921 Set_Name (Name_Node, Fname_Node);
922 Set_Parameter_Associations (Name_Node, Params_List);
923 return Name_Node;
924 end;
926 -- Case of call to attribute that denotes a procedure. Here we
927 -- just leave the attribute reference unchanged.
929 elsif Nkind (Name_Node) = N_Attribute_Reference
930 and then Is_Procedure_Attribute_Name (Attribute_Name (Name_Node))
931 then
932 return Name_Node;
934 -- All other cases of names are parameterless procedure calls
936 else
937 Stmt_Node :=
938 New_Node (N_Procedure_Call_Statement, Sloc (Name_Node));
939 Set_Name (Stmt_Node, Name_Node);
940 return Stmt_Node;
941 end if;
943 end P_Statement_Name;
945 ---------------------------
946 -- 5.1 Simple Statement --
947 ---------------------------
949 -- Parsed by P_Sequence_Of_Statements (5.1)
951 -----------------------------
952 -- 5.1 Compound Statement --
953 -----------------------------
955 -- Parsed by P_Sequence_Of_Statements (5.1)
957 -------------------------
958 -- 5.1 Null Statement --
959 -------------------------
961 -- NULL_STATEMENT ::= null;
963 -- The caller has already checked that the current token is null
965 -- Error recovery: cannot raise Error_Resync
967 function P_Null_Statement return Node_Id is
968 Null_Stmt_Node : Node_Id;
970 begin
971 Null_Stmt_Node := New_Node (N_Null_Statement, Token_Ptr);
972 Scan; -- past NULL
973 TF_Semicolon;
974 return Null_Stmt_Node;
975 end P_Null_Statement;
977 ----------------
978 -- 5.1 Label --
979 ----------------
981 -- LABEL ::= <<label_STATEMENT_IDENTIFIER>>
983 -- STATEMENT_IDENTIFIER ::= DIRECT_NAME
985 -- The IDENTIFIER of a STATEMENT_IDENTIFIER shall be an identifier
986 -- (not an OPERATOR_SYMBOL)
988 -- The caller has already checked that the current token is <<
990 -- Error recovery: can raise Error_Resync
992 function P_Label return Node_Id is
993 Label_Node : Node_Id;
995 begin
996 Label_Node := New_Node (N_Label, Token_Ptr);
997 Scan; -- past <<
998 Set_Identifier (Label_Node, P_Identifier);
999 T_Greater_Greater;
1000 Append_Elmt (Label_Node, Label_List);
1001 return Label_Node;
1002 end P_Label;
1004 -------------------------------
1005 -- 5.1 Statement Identifier --
1006 -------------------------------
1008 -- Statement label is parsed by P_Label (5.1)
1010 -- Loop label is parsed by P_Loop_Statement (5.5), P_For_Statement (5.5)
1011 -- or P_While_Statement (5.5)
1013 -- Block label is parsed by P_Begin_Statement (5.6) or
1014 -- P_Declare_Statement (5.6)
1016 -------------------------------
1017 -- 5.2 Assignment Statement --
1018 -------------------------------
1020 -- ASSIGNMENT_STATEMENT ::=
1021 -- variable_NAME := EXPRESSION;
1023 -- Error recovery: can raise Error_Resync
1025 function P_Assignment_Statement (LHS : Node_Id) return Node_Id is
1026 Assign_Node : Node_Id;
1028 begin
1029 Assign_Node := New_Node (N_Assignment_Statement, Prev_Token_Ptr);
1030 Set_Name (Assign_Node, LHS);
1031 Set_Expression (Assign_Node, P_Expression_No_Right_Paren);
1032 TF_Semicolon;
1033 return Assign_Node;
1034 end P_Assignment_Statement;
1036 -----------------------
1037 -- 5.3 If Statement --
1038 -----------------------
1040 -- IF_STATEMENT ::=
1041 -- if CONDITION then
1042 -- SEQUENCE_OF_STATEMENTS
1043 -- {elsif CONDITION then
1044 -- SEQUENCE_OF_STATEMENTS}
1045 -- [else
1046 -- SEQUENCE_OF_STATEMENTS]
1047 -- end if;
1049 -- The caller has checked that the initial token is IF (or in the error
1050 -- case of a mysterious THEN, the initial token may simply be THEN, in
1051 -- which case, no condition (or IF) was scanned).
1053 -- Error recovery: can raise Error_Resync
1055 function P_If_Statement return Node_Id is
1056 If_Node : Node_Id;
1057 Elsif_Node : Node_Id;
1058 Loc : Source_Ptr;
1060 procedure Add_Elsif_Part;
1061 -- An internal procedure used to scan out a single ELSIF part. On entry
1062 -- the ELSIF (or an ELSE which has been determined should be ELSIF) is
1063 -- scanned out and is in Prev_Token.
1065 procedure Check_If_Column;
1066 -- An internal procedure used to check that THEN, ELSE ELSE, or ELSIF
1067 -- appear in the right place if column checking is enabled (i.e. if
1068 -- they are the first token on the line, then they must appear in
1069 -- the same column as the opening IF).
1071 procedure Check_Then_Column;
1072 -- This procedure carries out the style checks for a THEN token
1073 -- Note that the caller has set Loc to the Source_Ptr value for
1074 -- the previous IF or ELSIF token. These checks apply only to a
1075 -- THEN at the start of a line.
1077 function Else_Should_Be_Elsif return Boolean;
1078 -- An internal routine used to do a special error recovery check when
1079 -- an ELSE is encountered. It determines if the ELSE should be treated
1080 -- as an ELSIF. A positive decision (TRUE returned, is made if the ELSE
1081 -- is followed by a sequence of tokens, starting on the same line as
1082 -- the ELSE, which are not expression terminators, followed by a THEN.
1083 -- On entry, the ELSE has been scanned out.
1085 procedure Add_Elsif_Part is
1086 begin
1087 if No (Elsif_Parts (If_Node)) then
1088 Set_Elsif_Parts (If_Node, New_List);
1089 end if;
1091 Elsif_Node := New_Node (N_Elsif_Part, Prev_Token_Ptr);
1092 Loc := Prev_Token_Ptr;
1093 Set_Condition (Elsif_Node, P_Condition);
1094 Check_Then_Column;
1095 Then_Scan;
1096 Set_Then_Statements
1097 (Elsif_Node, P_Sequence_Of_Statements (SS_Eftm_Eltm_Sreq));
1098 Append (Elsif_Node, Elsif_Parts (If_Node));
1099 end Add_Elsif_Part;
1101 procedure Check_If_Column is
1102 begin
1103 if Style.RM_Column_Check and then Token_Is_At_Start_Of_Line
1104 and then Start_Column /= Scope.Table (Scope.Last).Ecol
1105 then
1106 Error_Msg_Col := Scope.Table (Scope.Last).Ecol;
1107 Error_Msg_SC ("(style) this token should be@");
1108 end if;
1109 end Check_If_Column;
1111 procedure Check_Then_Column is
1112 begin
1113 if Token_Is_At_Start_Of_Line and then Token = Tok_Then then
1114 Check_If_Column;
1115 if Style_Check then Style.Check_Then (Loc); end if;
1116 end if;
1117 end Check_Then_Column;
1119 function Else_Should_Be_Elsif return Boolean is
1120 Scan_State : Saved_Scan_State;
1122 begin
1123 if Token_Is_At_Start_Of_Line then
1124 return False;
1126 else
1127 Save_Scan_State (Scan_State);
1129 loop
1130 if Token in Token_Class_Eterm then
1131 Restore_Scan_State (Scan_State);
1132 return False;
1133 else
1134 Scan; -- past non-expression terminating token
1136 if Token = Tok_Then then
1137 Restore_Scan_State (Scan_State);
1138 return True;
1139 end if;
1140 end if;
1141 end loop;
1142 end if;
1143 end Else_Should_Be_Elsif;
1145 -- Start of processing for P_If_Statement
1147 begin
1148 If_Node := New_Node (N_If_Statement, Token_Ptr);
1150 Push_Scope_Stack;
1151 Scope.Table (Scope.Last).Etyp := E_If;
1152 Scope.Table (Scope.Last).Ecol := Start_Column;
1153 Scope.Table (Scope.Last).Sloc := Token_Ptr;
1154 Scope.Table (Scope.Last).Labl := Error;
1155 Scope.Table (Scope.Last).Node := If_Node;
1157 if Token = Tok_If then
1158 Loc := Token_Ptr;
1159 Scan; -- past IF
1160 Set_Condition (If_Node, P_Condition);
1162 -- Deal with misuse of IF expression => used instead
1163 -- of WHEN expression =>
1165 if Token = Tok_Arrow then
1166 Error_Msg_SC ("THEN expected");
1167 Scan; -- past the arrow
1168 Pop_Scope_Stack; -- remove unneeded entry
1169 raise Error_Resync;
1170 end if;
1172 Check_Then_Column;
1174 else
1175 Error_Msg_SC ("no IF for this THEN");
1176 Set_Condition (If_Node, Error);
1177 end if;
1179 Then_Scan;
1181 Set_Then_Statements
1182 (If_Node, P_Sequence_Of_Statements (SS_Eftm_Eltm_Sreq));
1184 -- This loop scans out else and elsif parts
1186 loop
1187 if Token = Tok_Elsif then
1188 Check_If_Column;
1190 if Present (Else_Statements (If_Node)) then
1191 Error_Msg_SP ("ELSIF cannot appear after ELSE");
1192 end if;
1194 Scan; -- past ELSIF
1195 Add_Elsif_Part;
1197 elsif Token = Tok_Else then
1198 Check_If_Column;
1199 Scan; -- past ELSE
1201 if Else_Should_Be_Elsif then
1202 Error_Msg_SP ("ELSE should be ELSIF");
1203 Add_Elsif_Part;
1205 else
1206 -- Here we have an else that really is an else
1208 if Present (Else_Statements (If_Node)) then
1209 Error_Msg_SP ("Only one ELSE part allowed");
1210 Append_List
1211 (P_Sequence_Of_Statements (SS_Eftm_Eltm_Sreq),
1212 Else_Statements (If_Node));
1213 else
1214 Set_Else_Statements
1215 (If_Node, P_Sequence_Of_Statements (SS_Eftm_Eltm_Sreq));
1216 end if;
1217 end if;
1219 -- If anything other than ELSE or ELSIF, exit the loop. The token
1220 -- had better be END (and in fact it had better be END IF), but
1221 -- we will let End_Statements take care of checking that.
1223 else
1224 exit;
1225 end if;
1226 end loop;
1228 End_Statements;
1229 return If_Node;
1231 end P_If_Statement;
1233 --------------------
1234 -- 5.3 Condition --
1235 --------------------
1237 -- CONDITION ::= boolean_EXPRESSION
1239 function P_Condition return Node_Id is
1240 Cond : Node_Id;
1242 begin
1243 Cond := P_Expression_No_Right_Paren;
1245 -- It is never possible for := to follow a condition, so if we get
1246 -- a := we assume it is a mistyped equality. Note that we do not try
1247 -- to reconstruct the tree correctly in this case, but we do at least
1248 -- give an accurate error message.
1250 while Token = Tok_Colon_Equal loop
1251 Error_Msg_SC (""":="" should be ""=""");
1252 Scan; -- past junk :=
1253 Discard_Junk_Node (P_Expression_No_Right_Paren);
1254 end loop;
1256 return Cond;
1257 end P_Condition;
1259 -------------------------
1260 -- 5.4 Case Statement --
1261 -------------------------
1263 -- CASE_STATEMENT ::=
1264 -- case EXPRESSION is
1265 -- CASE_STATEMENT_ALTERNATIVE
1266 -- {CASE_STATEMENT_ALTERNATIVE}
1267 -- end case;
1269 -- The caller has checked that the first token is CASE
1271 -- Can raise Error_Resync
1273 function P_Case_Statement return Node_Id is
1274 Case_Node : Node_Id;
1275 Alternatives_List : List_Id;
1276 First_When_Loc : Source_Ptr;
1278 begin
1279 Case_Node := New_Node (N_Case_Statement, Token_Ptr);
1281 Push_Scope_Stack;
1282 Scope.Table (Scope.Last).Etyp := E_Case;
1283 Scope.Table (Scope.Last).Ecol := Start_Column;
1284 Scope.Table (Scope.Last).Sloc := Token_Ptr;
1285 Scope.Table (Scope.Last).Labl := Error;
1286 Scope.Table (Scope.Last).Node := Case_Node;
1288 Scan; -- past CASE
1289 Set_Expression (Case_Node, P_Expression_No_Right_Paren);
1290 TF_Is;
1292 -- Prepare to parse case statement alternatives
1294 Alternatives_List := New_List;
1295 P_Pragmas_Opt (Alternatives_List);
1296 First_When_Loc := Token_Ptr;
1298 -- Loop through case statement alternatives
1300 loop
1301 -- If we have a WHEN or OTHERS, then that's fine keep going. Note
1302 -- that it is a semantic check to ensure the proper use of OTHERS
1304 if Token = Tok_When or else Token = Tok_Others then
1305 Append (P_Case_Statement_Alternative, Alternatives_List);
1307 -- If we have an END, then probably we are at the end of the case
1308 -- but we only exit if Check_End thinks the END was reasonable.
1310 elsif Token = Tok_End then
1311 exit when Check_End;
1313 -- Here if token is other than WHEN, OTHERS or END. We definitely
1314 -- have an error, but the question is whether or not to get out of
1315 -- the case statement. We don't want to get out early, or we will
1316 -- get a slew of junk error messages for subsequent when tokens.
1318 -- If the token is not at the start of the line, or if it is indented
1319 -- with respect to the current case statement, then the best guess is
1320 -- that we are still supposed to be inside the case statement. We
1321 -- complain about the missing WHEN, and discard the junk statements.
1323 elsif not Token_Is_At_Start_Of_Line
1324 or else Start_Column > Scope.Table (Scope.Last).Ecol
1325 then
1326 Error_Msg_BC ("WHEN (case statement alternative) expected");
1328 -- Here is a possibility for infinite looping if we don't make
1329 -- progress. So try to process statements, otherwise exit
1331 declare
1332 Error_Ptr : constant Source_Ptr := Scan_Ptr;
1333 begin
1334 Discard_Junk_List (P_Sequence_Of_Statements (SS_Whtm));
1335 exit when Scan_Ptr = Error_Ptr and then Check_End;
1336 end;
1338 -- Here we have a junk token at the start of the line and it is
1339 -- not indented. If Check_End thinks there is a missing END, then
1340 -- we will get out of the case, otherwise we keep going.
1342 else
1343 exit when Check_End;
1344 end if;
1345 end loop;
1347 -- Make sure we have at least one alternative
1349 if No (First_Non_Pragma (Alternatives_List)) then
1350 Error_Msg
1351 ("WHEN expected, must have at least one alternative in case",
1352 First_When_Loc);
1353 return Error;
1355 else
1356 Set_Alternatives (Case_Node, Alternatives_List);
1357 return Case_Node;
1358 end if;
1359 end P_Case_Statement;
1361 -------------------------------------
1362 -- 5.4 Case Statement Alternative --
1363 -------------------------------------
1365 -- CASE_STATEMENT_ALTERNATIVE ::=
1366 -- when DISCRETE_CHOICE_LIST =>
1367 -- SEQUENCE_OF_STATEMENTS
1369 -- The caller has checked that the initial token is WHEN or OTHERS
1370 -- Error recovery: can raise Error_Resync
1372 function P_Case_Statement_Alternative return Node_Id is
1373 Case_Alt_Node : Node_Id;
1375 begin
1376 if Style_Check then Style.Check_Indentation; end if;
1377 Case_Alt_Node := New_Node (N_Case_Statement_Alternative, Token_Ptr);
1378 T_When; -- past WHEN (or give error in OTHERS case)
1379 Set_Discrete_Choices (Case_Alt_Node, P_Discrete_Choice_List);
1380 TF_Arrow;
1381 Set_Statements (Case_Alt_Node, P_Sequence_Of_Statements (SS_Sreq_Whtm));
1382 return Case_Alt_Node;
1383 end P_Case_Statement_Alternative;
1385 -------------------------
1386 -- 5.5 Loop Statement --
1387 -------------------------
1389 -- LOOP_STATEMENT ::=
1390 -- [LOOP_STATEMENT_IDENTIFIER:]
1391 -- [ITERATION_SCHEME] loop
1392 -- SEQUENCE_OF_STATEMENTS
1393 -- end loop [loop_IDENTIFIER];
1395 -- ITERATION_SCHEME ::=
1396 -- while CONDITION
1397 -- | for LOOP_PARAMETER_SPECIFICATION
1399 -- The parsing of loop statements is handled by one of three functions
1400 -- P_Loop_Statement, P_For_Statement or P_While_Statement depending
1401 -- on the initial keyword in the construct (excluding the identifier)
1403 -- P_Loop_Statement
1405 -- This function parses the case where no iteration scheme is present
1407 -- The caller has checked that the initial token is LOOP. The parameter
1408 -- is the node identifiers for the loop label if any (or is set to Empty
1409 -- if there is no loop label).
1411 -- Error recovery : cannot raise Error_Resync
1413 function P_Loop_Statement (Loop_Name : Node_Id := Empty) return Node_Id is
1414 Loop_Node : Node_Id;
1416 begin
1417 Push_Scope_Stack;
1418 Scope.Table (Scope.Last).Labl := Loop_Name;
1419 Scope.Table (Scope.Last).Ecol := Start_Column;
1420 Scope.Table (Scope.Last).Sloc := Token_Ptr;
1421 Scope.Table (Scope.Last).Etyp := E_Loop;
1423 Loop_Node := New_Node (N_Loop_Statement, Token_Ptr);
1424 TF_Loop;
1426 if No (Loop_Name) then
1427 Set_Has_Created_Identifier (Loop_Node, True);
1428 Set_Identifier (Loop_Node,
1429 Make_Identifier (Sloc (Loop_Node), Set_Loop_Block_Name ('L')));
1430 else
1431 Set_Identifier (Loop_Node, Loop_Name);
1432 end if;
1434 Append_Elmt (Loop_Node, Label_List);
1436 Set_Statements (Loop_Node, P_Sequence_Of_Statements (SS_Sreq));
1437 End_Statements (Loop_Node);
1438 return Loop_Node;
1439 end P_Loop_Statement;
1441 -- P_For_Statement
1443 -- This function parses a loop statement with a FOR iteration scheme
1445 -- The caller has checked that the initial token is FOR. The parameter
1446 -- is the node identifier for the block label if any (or is set to Empty
1447 -- if there is no block label).
1449 -- Note: the caller fills in the Identifier field if a label was present
1451 -- Error recovery: can raise Error_Resync
1453 function P_For_Statement (Loop_Name : Node_Id := Empty) return Node_Id is
1454 Loop_Node : Node_Id;
1455 Iter_Scheme_Node : Node_Id;
1456 Loop_For_Flag : Boolean;
1458 begin
1459 Push_Scope_Stack;
1460 Scope.Table (Scope.Last).Labl := Loop_Name;
1461 Scope.Table (Scope.Last).Ecol := Start_Column;
1462 Scope.Table (Scope.Last).Sloc := Token_Ptr;
1463 Scope.Table (Scope.Last).Etyp := E_Loop;
1465 Loop_For_Flag := (Prev_Token = Tok_Loop);
1466 Scan; -- past FOR
1467 Iter_Scheme_Node := New_Node (N_Iteration_Scheme, Token_Ptr);
1468 Set_Loop_Parameter_Specification
1469 (Iter_Scheme_Node, P_Loop_Parameter_Specification);
1471 -- The following is a special test so that a miswritten for loop such
1472 -- as "loop for I in 1..10;" is handled nicely, without making an extra
1473 -- entry in the scope stack. We don't bother to actually fix up the
1474 -- tree in this case since it's not worth the effort. Instead we just
1475 -- eat up the loop junk, leaving the entry for what now looks like an
1476 -- unmodified loop intact.
1478 if Loop_For_Flag and then Token = Tok_Semicolon then
1479 Error_Msg_SC ("LOOP belongs here, not before FOR");
1480 Pop_Scope_Stack;
1481 return Error;
1483 -- Normal case
1485 else
1486 Loop_Node := New_Node (N_Loop_Statement, Token_Ptr);
1487 TF_Loop;
1488 Set_Statements (Loop_Node, P_Sequence_Of_Statements (SS_Sreq));
1489 End_Statements (Loop_Node);
1490 Set_Iteration_Scheme (Loop_Node, Iter_Scheme_Node);
1492 if No (Loop_Name) then
1493 Set_Has_Created_Identifier (Loop_Node, True);
1494 Set_Identifier (Loop_Node,
1495 Make_Identifier (Sloc (Loop_Node), Set_Loop_Block_Name ('L')));
1496 else
1497 Set_Identifier (Loop_Node, Loop_Name);
1498 end if;
1500 Append_Elmt (Loop_Node, Label_List);
1502 return Loop_Node;
1503 end if;
1505 end P_For_Statement;
1507 -- P_While_Statement
1509 -- This procedure scans a loop statement with a WHILE iteration scheme
1511 -- The caller has checked that the initial token is WHILE. The parameter
1512 -- is the node identifier for the block label if any (or is set to Empty
1513 -- if there is no block label).
1515 -- Error recovery: cannot raise Error_Resync
1517 function P_While_Statement (Loop_Name : Node_Id := Empty) return Node_Id is
1518 Loop_Node : Node_Id;
1519 Iter_Scheme_Node : Node_Id;
1520 Loop_While_Flag : Boolean;
1522 begin
1523 Push_Scope_Stack;
1524 Scope.Table (Scope.Last).Labl := Loop_Name;
1525 Scope.Table (Scope.Last).Ecol := Start_Column;
1526 Scope.Table (Scope.Last).Sloc := Token_Ptr;
1527 Scope.Table (Scope.Last).Etyp := E_Loop;
1529 Loop_While_Flag := (Prev_Token = Tok_Loop);
1530 Iter_Scheme_Node := New_Node (N_Iteration_Scheme, Token_Ptr);
1531 Scan; -- past WHILE
1532 Set_Condition (Iter_Scheme_Node, P_Condition);
1534 -- The following is a special test so that a miswritten for loop such
1535 -- as "loop while I > 10;" is handled nicely, without making an extra
1536 -- entry in the scope stack. We don't bother to actually fix up the
1537 -- tree in this case since it's not worth the effort. Instead we just
1538 -- eat up the loop junk, leaving the entry for what now looks like an
1539 -- unmodified loop intact.
1541 if Loop_While_Flag and then Token = Tok_Semicolon then
1542 Error_Msg_SC ("LOOP belongs here, not before WHILE");
1543 Pop_Scope_Stack;
1544 return Error;
1546 -- Normal case
1548 else
1549 Loop_Node := New_Node (N_Loop_Statement, Token_Ptr);
1550 TF_Loop;
1551 Set_Statements (Loop_Node, P_Sequence_Of_Statements (SS_Sreq));
1552 End_Statements (Loop_Node);
1553 Set_Iteration_Scheme (Loop_Node, Iter_Scheme_Node);
1555 if No (Loop_Name) then
1556 Set_Has_Created_Identifier (Loop_Node, True);
1557 Set_Identifier (Loop_Node,
1558 Make_Identifier (Sloc (Loop_Node), Set_Loop_Block_Name ('L')));
1559 else
1560 Set_Identifier (Loop_Node, Loop_Name);
1561 end if;
1563 Append_Elmt (Loop_Node, Label_List);
1565 return Loop_Node;
1566 end if;
1568 end P_While_Statement;
1570 ---------------------------------------
1571 -- 5.5 Loop Parameter Specification --
1572 ---------------------------------------
1574 -- LOOP_PARAMETER_SPECIFICATION ::=
1575 -- DEFINING_IDENTIFIER in [reverse] DISCRETE_SUBTYPE_DEFINITION
1577 -- Error recovery: cannot raise Error_Resync
1579 function P_Loop_Parameter_Specification return Node_Id is
1580 Loop_Param_Specification_Node : Node_Id;
1582 ID_Node : Node_Id;
1583 Scan_State : Saved_Scan_State;
1585 begin
1586 Loop_Param_Specification_Node :=
1587 New_Node (N_Loop_Parameter_Specification, Token_Ptr);
1589 Save_Scan_State (Scan_State);
1590 ID_Node := P_Defining_Identifier;
1591 Set_Defining_Identifier (Loop_Param_Specification_Node, ID_Node);
1593 if Token = Tok_Left_Paren then
1594 Error_Msg_SC ("subscripted loop parameter not allowed");
1595 Restore_Scan_State (Scan_State);
1596 Discard_Junk_Node (P_Name);
1598 elsif Token = Tok_Dot then
1599 Error_Msg_SC ("selected loop parameter not allowed");
1600 Restore_Scan_State (Scan_State);
1601 Discard_Junk_Node (P_Name);
1602 end if;
1604 T_In;
1606 if Token = Tok_Reverse then
1607 Scan; -- past REVERSE
1608 Set_Reverse_Present (Loop_Param_Specification_Node, True);
1609 end if;
1611 Set_Discrete_Subtype_Definition
1612 (Loop_Param_Specification_Node, P_Discrete_Subtype_Definition);
1613 return Loop_Param_Specification_Node;
1615 exception
1616 when Error_Resync =>
1617 return Error;
1618 end P_Loop_Parameter_Specification;
1620 --------------------------
1621 -- 5.6 Block Statement --
1622 --------------------------
1624 -- BLOCK_STATEMENT ::=
1625 -- [block_STATEMENT_IDENTIFIER:]
1626 -- [declare
1627 -- DECLARATIVE_PART]
1628 -- begin
1629 -- HANDLED_SEQUENCE_OF_STATEMENTS
1630 -- end [block_IDENTIFIER];
1632 -- The parsing of block statements is handled by one of the two functions
1633 -- P_Declare_Statement or P_Begin_Statement depending on whether or not
1634 -- a declare section is present
1636 -- P_Declare_Statement
1638 -- This function parses a block statement with DECLARE present
1640 -- The caller has checked that the initial token is DECLARE.
1642 -- Error recovery: cannot raise Error_Resync
1644 function P_Declare_Statement
1645 (Block_Name : Node_Id := Empty)
1646 return Node_Id
1648 Block_Node : Node_Id;
1650 begin
1651 Block_Node := New_Node (N_Block_Statement, Token_Ptr);
1653 Push_Scope_Stack;
1654 Scope.Table (Scope.Last).Etyp := E_Name;
1655 Scope.Table (Scope.Last).Lreq := Present (Block_Name);
1656 Scope.Table (Scope.Last).Ecol := Start_Column;
1657 Scope.Table (Scope.Last).Labl := Block_Name;
1658 Scope.Table (Scope.Last).Sloc := Token_Ptr;
1660 Scan; -- past DECLARE
1662 if No (Block_Name) then
1663 Set_Has_Created_Identifier (Block_Node, True);
1664 Set_Identifier (Block_Node,
1665 Make_Identifier (Sloc (Block_Node), Set_Loop_Block_Name ('B')));
1666 else
1667 Set_Identifier (Block_Node, Block_Name);
1668 end if;
1670 Append_Elmt (Block_Node, Label_List);
1671 Parse_Decls_Begin_End (Block_Node);
1672 return Block_Node;
1673 end P_Declare_Statement;
1675 -- P_Begin_Statement
1677 -- This function parses a block statement with no DECLARE present
1679 -- The caller has checked that the initial token is BEGIN
1681 -- Error recovery: cannot raise Error_Resync
1683 function P_Begin_Statement
1684 (Block_Name : Node_Id := Empty)
1685 return Node_Id
1687 Block_Node : Node_Id;
1689 begin
1690 Block_Node := New_Node (N_Block_Statement, Token_Ptr);
1692 Push_Scope_Stack;
1693 Scope.Table (Scope.Last).Etyp := E_Name;
1694 Scope.Table (Scope.Last).Lreq := Present (Block_Name);
1695 Scope.Table (Scope.Last).Ecol := Start_Column;
1696 Scope.Table (Scope.Last).Labl := Block_Name;
1697 Scope.Table (Scope.Last).Sloc := Token_Ptr;
1699 if No (Block_Name) then
1700 Set_Has_Created_Identifier (Block_Node, True);
1701 Set_Identifier (Block_Node,
1702 Make_Identifier (Sloc (Block_Node), Set_Loop_Block_Name ('B')));
1703 else
1704 Set_Identifier (Block_Node, Block_Name);
1705 end if;
1707 Append_Elmt (Block_Node, Label_List);
1709 Scope.Table (Scope.Last).Ecol := Start_Column;
1710 Scope.Table (Scope.Last).Sloc := Token_Ptr;
1711 Scan; -- past BEGIN
1712 Set_Handled_Statement_Sequence
1713 (Block_Node, P_Handled_Sequence_Of_Statements);
1714 End_Statements (Handled_Statement_Sequence (Block_Node));
1715 return Block_Node;
1716 end P_Begin_Statement;
1718 -------------------------
1719 -- 5.7 Exit Statement --
1720 -------------------------
1722 -- EXIT_STATEMENT ::=
1723 -- exit [loop_NAME] [when CONDITION];
1725 -- The caller has checked that the initial token is EXIT
1727 -- Error recovery: can raise Error_Resync
1729 function P_Exit_Statement return Node_Id is
1730 Exit_Node : Node_Id;
1732 function Missing_Semicolon_On_Exit return Boolean;
1733 -- This function deals with the following specialized situation
1735 -- when 'x' =>
1736 -- exit [identifier]
1737 -- when 'y' =>
1739 -- This looks like a messed up EXIT WHEN, when in fact the problem
1740 -- is a missing semicolon. It is called with Token pointing to the
1741 -- WHEN token, and returns True if a semicolon is missing before
1742 -- the WHEN as in the above example.
1744 function Missing_Semicolon_On_Exit return Boolean is
1745 State : Saved_Scan_State;
1747 begin
1748 if not Token_Is_At_Start_Of_Line then
1749 return False;
1751 elsif Scope.Table (Scope.Last).Etyp /= E_Case then
1752 return False;
1754 else
1755 Save_Scan_State (State);
1756 Scan; -- past WHEN
1757 Scan; -- past token after WHEN
1759 if Token = Tok_Arrow then
1760 Restore_Scan_State (State);
1761 return True;
1762 else
1763 Restore_Scan_State (State);
1764 return False;
1765 end if;
1766 end if;
1767 end Missing_Semicolon_On_Exit;
1769 -- Start of processing for P_Exit_Statement
1771 begin
1772 Exit_Node := New_Node (N_Exit_Statement, Token_Ptr);
1773 Scan; -- past EXIT
1775 if Token = Tok_Identifier then
1776 Set_Name (Exit_Node, P_Qualified_Simple_Name);
1778 elsif Style_Check then
1779 -- This EXIT has no name, so check that
1780 -- the innermost loop is unnamed too.
1782 Check_No_Exit_Name :
1783 for J in reverse 1 .. Scope.Last loop
1784 if Scope.Table (J).Etyp = E_Loop then
1785 if Present (Scope.Table (J).Labl) then
1787 -- Innermost loop in fact had a name, style check fails
1789 Style.No_Exit_Name (Scope.Table (J).Labl);
1790 end if;
1792 exit Check_No_Exit_Name;
1793 end if;
1794 end loop Check_No_Exit_Name;
1795 end if;
1797 if Token = Tok_When and then not Missing_Semicolon_On_Exit then
1798 Scan; -- past WHEN
1799 Set_Condition (Exit_Node, P_Condition);
1801 -- Allow IF instead of WHEN, giving error message
1803 elsif Token = Tok_If then
1804 T_When;
1805 Scan; -- past IF used in place of WHEN
1806 Set_Condition (Exit_Node, P_Expression_No_Right_Paren);
1807 end if;
1809 TF_Semicolon;
1810 return Exit_Node;
1811 end P_Exit_Statement;
1813 -------------------------
1814 -- 5.8 Goto Statement --
1815 -------------------------
1817 -- GOTO_STATEMENT ::= goto label_NAME;
1819 -- The caller has checked that the initial token is GOTO (or TO in the
1820 -- error case where GO and TO were incorrectly separated).
1822 -- Error recovery: can raise Error_Resync
1824 function P_Goto_Statement return Node_Id is
1825 Goto_Node : Node_Id;
1827 begin
1828 Goto_Node := New_Node (N_Goto_Statement, Token_Ptr);
1829 Scan; -- past GOTO (or TO)
1830 Set_Name (Goto_Node, P_Qualified_Simple_Name_Resync);
1831 No_Constraint;
1832 TF_Semicolon;
1833 return Goto_Node;
1834 end P_Goto_Statement;
1836 ---------------------------
1837 -- Parse_Decls_Begin_End --
1838 ---------------------------
1840 -- This function parses the construct:
1842 -- DECLARATIVE_PART
1843 -- begin
1844 -- HANDLED_SEQUENCE_OF_STATEMENTS
1845 -- end [NAME];
1847 -- The caller has built the scope stack entry, and created the node to
1848 -- whose Declarations and Handled_Statement_Sequence fields are to be
1849 -- set. On return these fields are filled in (except in the case of a
1850 -- task body, where the handled statement sequence is optional, and may
1851 -- thus be Empty), and the scan is positioned past the End sequence.
1853 -- If the BEGIN is missing, then the parent node is used to help construct
1854 -- an appropriate missing BEGIN message. Possibilities for the parent are:
1856 -- N_Block_Statement declare block
1857 -- N_Entry_Body entry body
1858 -- N_Package_Body package body (begin part optional)
1859 -- N_Subprogram_Body procedure or function body
1860 -- N_Task_Body task body
1862 -- Note: in the case of a block statement, there is definitely a DECLARE
1863 -- present (because a Begin statement without a DECLARE is handled by the
1864 -- P_Begin_Statement procedure, which does not call Parse_Decls_Begin_End.
1866 -- Error recovery: cannot raise Error_Resync
1868 procedure Parse_Decls_Begin_End (Parent : Node_Id) is
1869 Body_Decl : Node_Id;
1870 Body_Sloc : Source_Ptr;
1871 Decls : List_Id;
1872 Decl : Node_Id;
1873 Parent_Nkind : Node_Kind;
1874 Spec_Node : Node_Id;
1875 HSS : Node_Id;
1877 procedure Missing_Begin (Msg : String);
1878 -- Called to post a missing begin message. In the normal case this is
1879 -- posted at the start of the current token. A special case arises when
1880 -- P_Declarative_Items has previously found a missing begin, in which
1881 -- case we replace the original error message.
1883 procedure Set_Null_HSS (Parent : Node_Id);
1884 -- Construct an empty handled statement sequence and install in Parent
1885 -- Leaves HSS set to reference the newly constructed statement sequence.
1887 -------------------
1888 -- Missing_Begin --
1889 -------------------
1891 procedure Missing_Begin (Msg : String) is
1892 begin
1893 if Missing_Begin_Msg = No_Error_Msg then
1894 Error_Msg_BC (Msg);
1895 else
1896 Change_Error_Text (Missing_Begin_Msg, Msg);
1898 -- Purge any messages issued after than, since a missing begin
1899 -- can cause a lot of havoc, and it is better not to dump these
1900 -- cascaded messages on the user.
1902 Purge_Messages (Get_Location (Missing_Begin_Msg), Prev_Token_Ptr);
1903 end if;
1904 end Missing_Begin;
1906 ------------------
1907 -- Set_Null_HSS --
1908 ------------------
1910 procedure Set_Null_HSS (Parent : Node_Id) is
1911 Null_Stm : Node_Id;
1913 begin
1914 Null_Stm :=
1915 Make_Null_Statement (Token_Ptr);
1916 Set_Comes_From_Source (Null_Stm, False);
1918 HSS :=
1919 Make_Handled_Sequence_Of_Statements (Token_Ptr,
1920 Statements => New_List (Null_Stm));
1921 Set_Comes_From_Source (HSS, False);
1923 Set_Handled_Statement_Sequence (Parent, HSS);
1924 end Set_Null_HSS;
1926 -- Start of processing for Parse_Decls_Begin_End
1928 begin
1929 Decls := P_Declarative_Part;
1931 -- Check for misplacement of later vs basic declarations in Ada 83
1933 if Ada_83 then
1934 Decl := First (Decls);
1936 -- Loop through sequence of basic declarative items
1938 Outer : while Present (Decl) loop
1939 if Nkind (Decl) /= N_Subprogram_Body
1940 and then Nkind (Decl) /= N_Package_Body
1941 and then Nkind (Decl) /= N_Task_Body
1942 and then Nkind (Decl) not in N_Body_Stub
1943 then
1944 Next (Decl);
1946 -- Once a body is encountered, we only allow later declarative
1947 -- items. The inner loop checks the rest of the list.
1949 else
1950 Body_Sloc := Sloc (Decl);
1952 Inner : while Present (Decl) loop
1953 if Nkind (Decl) not in N_Later_Decl_Item
1954 and then Nkind (Decl) /= N_Pragma
1955 then
1956 if Ada_83 then
1957 Error_Msg_Sloc := Body_Sloc;
1958 Error_Msg_N
1959 ("(Ada 83) decl cannot appear after body#", Decl);
1960 end if;
1961 end if;
1963 Next (Decl);
1964 end loop Inner;
1965 end if;
1966 end loop Outer;
1967 end if;
1969 -- Here is where we deal with the case of IS used instead of semicolon.
1970 -- Specifically, if the last declaration in the declarative part is a
1971 -- subprogram body still marked as having a bad IS, then this is where
1972 -- we decide that the IS should really have been a semicolon and that
1973 -- the body should have been a declaration. Note that if the bad IS
1974 -- had turned out to be OK (i.e. a decent begin/end was found for it),
1975 -- then the Bad_Is_Detected flag would have been reset by now.
1977 Body_Decl := Last (Decls);
1979 if Present (Body_Decl)
1980 and then Nkind (Body_Decl) = N_Subprogram_Body
1981 and then Bad_Is_Detected (Body_Decl)
1982 then
1983 -- OK, we have the case of a bad IS, so we need to fix up the tree.
1984 -- What we have now is a subprogram body with attached declarations
1985 -- and a possible statement sequence.
1987 -- First step is to take the declarations that were part of the bogus
1988 -- subprogram body and append them to the outer declaration chain.
1989 -- In other words we append them past the body (which we will later
1990 -- convert into a declaration).
1992 Append_List (Declarations (Body_Decl), Decls);
1994 -- Now take the handled statement sequence of the bogus body and
1995 -- set it as the statement sequence for the outer construct. Note
1996 -- that it may be empty (we specially allowed a missing BEGIN for
1997 -- a subprogram body marked as having a bad IS -- see below).
1999 Set_Handled_Statement_Sequence (Parent,
2000 Handled_Statement_Sequence (Body_Decl));
2002 -- Next step is to convert the old body node to a declaration node
2004 Spec_Node := Specification (Body_Decl);
2005 Change_Node (Body_Decl, N_Subprogram_Declaration);
2006 Set_Specification (Body_Decl, Spec_Node);
2008 -- Final step is to put the declarations for the parent where
2009 -- they belong, and then fall through the IF to scan out the
2010 -- END statements.
2012 Set_Declarations (Parent, Decls);
2014 -- This is the normal case (i.e. any case except the bad IS case)
2015 -- If we have a BEGIN, then scan out the sequence of statements, and
2016 -- also reset the expected column for the END to match the BEGIN.
2018 else
2019 Set_Declarations (Parent, Decls);
2021 if Token = Tok_Begin then
2022 if Style_Check then Style.Check_Indentation; end if;
2024 Error_Msg_Col := Scope.Table (Scope.Last).Ecol;
2026 if Style.RM_Column_Check
2027 and then Token_Is_At_Start_Of_Line
2028 and then Start_Column /= Error_Msg_Col
2029 then
2030 Error_Msg_SC ("(style) BEGIN in wrong column, should be@");
2032 else
2033 Scope.Table (Scope.Last).Ecol := Start_Column;
2034 end if;
2036 Scope.Table (Scope.Last).Sloc := Token_Ptr;
2037 Scan; -- past BEGIN
2038 Set_Handled_Statement_Sequence (Parent,
2039 P_Handled_Sequence_Of_Statements);
2041 -- No BEGIN present
2043 else
2044 Parent_Nkind := Nkind (Parent);
2046 -- A special check for the missing IS case. If we have a
2047 -- subprogram body that was marked as having a suspicious
2048 -- IS, and the current token is END, then we simply confirm
2049 -- the suspicion, and do not require a BEGIN to be present
2051 if Parent_Nkind = N_Subprogram_Body
2052 and then Token = Tok_End
2053 and then Scope.Table (Scope.Last).Etyp = E_Suspicious_Is
2054 then
2055 Scope.Table (Scope.Last).Etyp := E_Bad_Is;
2057 -- Otherwise BEGIN is not required for a package body, so we
2058 -- don't mind if it is missing, but we do construct a dummy
2059 -- one (so that we have somewhere to set End_Label).
2061 -- However if we have something other than a BEGIN which
2062 -- looks like it might be statements, then we signal a missing
2063 -- BEGIN for these cases as well. We define "something which
2064 -- looks like it might be statements" as a token other than
2065 -- END, EOF, or a token which starts declarations.
2067 elsif Parent_Nkind = N_Package_Body
2068 and then (Token = Tok_End
2069 or else Token = Tok_EOF
2070 or else Token in Token_Class_Declk)
2071 then
2072 Set_Null_HSS (Parent);
2074 -- These are cases in which a BEGIN is required and not present
2076 else
2077 Set_Null_HSS (Parent);
2079 -- Prepare to issue error message
2081 Error_Msg_Sloc := Scope.Table (Scope.Last).Sloc;
2082 Error_Msg_Node_1 := Scope.Table (Scope.Last).Labl;
2084 -- Now issue appropriate message
2086 if Parent_Nkind = N_Block_Statement then
2087 Missing_Begin ("missing BEGIN for DECLARE#!");
2089 elsif Parent_Nkind = N_Entry_Body then
2090 Missing_Begin ("missing BEGIN for ENTRY#!");
2092 elsif Parent_Nkind = N_Subprogram_Body then
2093 if Nkind (Specification (Parent))
2094 = N_Function_Specification
2095 then
2096 Missing_Begin ("missing BEGIN for function&#!");
2097 else
2098 Missing_Begin ("missing BEGIN for procedure&#!");
2099 end if;
2101 -- The case for package body arises only when
2102 -- we have possible statement junk present.
2104 elsif Parent_Nkind = N_Package_Body then
2105 Missing_Begin ("missing BEGIN for package body&#!");
2107 else
2108 pragma Assert (Parent_Nkind = N_Task_Body);
2109 Missing_Begin ("missing BEGIN for task body&#!");
2110 end if;
2112 -- Here we pick up the statements after the BEGIN that
2113 -- should have been present but was not. We don't insist
2114 -- on statements being present if P_Declarative_Part had
2115 -- already found a missing BEGIN, since it might have
2116 -- swallowed a lone statement into the declarative part.
2118 if Missing_Begin_Msg /= No_Error_Msg
2119 and then Token = Tok_End
2120 then
2121 null;
2122 else
2123 Set_Handled_Statement_Sequence (Parent,
2124 P_Handled_Sequence_Of_Statements);
2125 end if;
2126 end if;
2127 end if;
2128 end if;
2130 -- Here with declarations and handled statement sequence scanned
2132 if Present (Handled_Statement_Sequence (Parent)) then
2133 End_Statements (Handled_Statement_Sequence (Parent));
2134 else
2135 End_Statements;
2136 end if;
2138 -- We know that End_Statements removed an entry from the scope stack
2139 -- (because it is required to do so under all circumstances). We can
2140 -- therefore reference the entry it removed one past the stack top.
2141 -- What we are interested in is whether it was a case of a bad IS.
2143 if Scope.Table (Scope.Last + 1).Etyp = E_Bad_Is then
2144 Error_Msg ("IS should be "";""", Scope.Table (Scope.Last + 1).S_Is);
2145 Set_Bad_Is_Detected (Parent, True);
2146 end if;
2148 end Parse_Decls_Begin_End;
2150 -------------------------
2151 -- Set_Loop_Block_Name --
2152 -------------------------
2154 function Set_Loop_Block_Name (L : Character) return Name_Id is
2155 begin
2156 Name_Buffer (1) := L;
2157 Name_Buffer (2) := '_';
2158 Name_Len := 2;
2159 Loop_Block_Count := Loop_Block_Count + 1;
2160 Add_Nat_To_Name_Buffer (Loop_Block_Count);
2161 return Name_Find;
2162 end Set_Loop_Block_Name;
2164 ---------------
2165 -- Then_Scan --
2166 ---------------
2168 procedure Then_Scan is
2169 begin
2170 TF_Then;
2172 while Token = Tok_Then loop
2173 Error_Msg_SC ("redundant THEN");
2174 TF_Then;
2175 end loop;
2177 if Token = Tok_And or else Token = Tok_Or then
2178 Error_Msg_SC ("unexpected logical operator");
2179 Scan;
2181 if (Prev_Token = Tok_And and then Token = Tok_Then)
2182 or else
2183 (Prev_Token = Tok_Or and then Token = Tok_Else)
2184 then
2185 Scan;
2186 end if;
2188 Discard_Junk_Node (P_Expression);
2189 end if;
2191 if Token = Tok_Then then
2192 Scan;
2193 end if;
2194 end Then_Scan;
2196 end Ch5;