annotate gcc/ada/par-ch5.adb @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ------------------------------------------------------------------------------
kono
parents:
diff changeset
2 -- --
kono
parents:
diff changeset
3 -- GNAT COMPILER COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- P A R . C H 5 --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- B o d y --
kono
parents:
diff changeset
8 -- --
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
9 -- Copyright (C) 1992-2018, Free Software Foundation, Inc. --
111
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- GNAT is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
12 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
kono
parents:
diff changeset
17 -- for more details. You should have received a copy of the GNU General --
kono
parents:
diff changeset
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
kono
parents:
diff changeset
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
kono
parents:
diff changeset
20 -- --
kono
parents:
diff changeset
21 -- GNAT was originally developed by the GNAT team at New York University. --
kono
parents:
diff changeset
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
kono
parents:
diff changeset
23 -- --
kono
parents:
diff changeset
24 ------------------------------------------------------------------------------
kono
parents:
diff changeset
25
kono
parents:
diff changeset
26 pragma Style_Checks (All_Checks);
kono
parents:
diff changeset
27 -- Turn off subprogram body ordering check. Subprograms are in order by RM
kono
parents:
diff changeset
28 -- section rather than alphabetical.
kono
parents:
diff changeset
29
kono
parents:
diff changeset
30 with Sinfo.CN; use Sinfo.CN;
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 separate (Par)
kono
parents:
diff changeset
33 package body Ch5 is
kono
parents:
diff changeset
34
kono
parents:
diff changeset
35 -- Local functions, used only in this chapter
kono
parents:
diff changeset
36
kono
parents:
diff changeset
37 function P_Case_Statement return Node_Id;
kono
parents:
diff changeset
38 function P_Case_Statement_Alternative return Node_Id;
kono
parents:
diff changeset
39 function P_Exit_Statement return Node_Id;
kono
parents:
diff changeset
40 function P_Goto_Statement return Node_Id;
kono
parents:
diff changeset
41 function P_If_Statement return Node_Id;
kono
parents:
diff changeset
42 function P_Label return Node_Id;
kono
parents:
diff changeset
43 function P_Null_Statement return Node_Id;
kono
parents:
diff changeset
44
kono
parents:
diff changeset
45 function P_Assignment_Statement (LHS : Node_Id) return Node_Id;
kono
parents:
diff changeset
46 -- Parse assignment statement. On entry, the caller has scanned the left
kono
parents:
diff changeset
47 -- hand side (passed in as Lhs), and the colon-equal (or some symbol
kono
parents:
diff changeset
48 -- taken to be an error equivalent such as equal).
kono
parents:
diff changeset
49
kono
parents:
diff changeset
50 function P_Begin_Statement (Block_Name : Node_Id := Empty) return Node_Id;
kono
parents:
diff changeset
51 -- Parse begin-end statement. If Block_Name is non-Empty on entry, it is
kono
parents:
diff changeset
52 -- the N_Identifier node for the label on the block. If Block_Name is
kono
parents:
diff changeset
53 -- Empty on entry (the default), then the block statement is unlabeled.
kono
parents:
diff changeset
54
kono
parents:
diff changeset
55 function P_Declare_Statement (Block_Name : Node_Id := Empty) return Node_Id;
kono
parents:
diff changeset
56 -- Parse declare block. If Block_Name is non-Empty on entry, it is
kono
parents:
diff changeset
57 -- the N_Identifier node for the label on the block. If Block_Name is
kono
parents:
diff changeset
58 -- Empty on entry (the default), then the block statement is unlabeled.
kono
parents:
diff changeset
59
kono
parents:
diff changeset
60 function P_For_Statement (Loop_Name : Node_Id := Empty) return Node_Id;
kono
parents:
diff changeset
61 -- Parse for statement. If Loop_Name is non-Empty on entry, it is
kono
parents:
diff changeset
62 -- the N_Identifier node for the label on the loop. If Loop_Name is
kono
parents:
diff changeset
63 -- Empty on entry (the default), then the for statement is unlabeled.
kono
parents:
diff changeset
64
kono
parents:
diff changeset
65 function P_Iterator_Specification (Def_Id : Node_Id) return Node_Id;
kono
parents:
diff changeset
66 -- Parse an iterator specification. The defining identifier has already
kono
parents:
diff changeset
67 -- been scanned, as it is the common prefix between loop and iterator
kono
parents:
diff changeset
68 -- specification.
kono
parents:
diff changeset
69
kono
parents:
diff changeset
70 function P_Loop_Statement (Loop_Name : Node_Id := Empty) return Node_Id;
kono
parents:
diff changeset
71 -- Parse loop statement. If Loop_Name is non-Empty on entry, it is
kono
parents:
diff changeset
72 -- the N_Identifier node for the label on the loop. If Loop_Name is
kono
parents:
diff changeset
73 -- Empty on entry (the default), then the loop statement is unlabeled.
kono
parents:
diff changeset
74
kono
parents:
diff changeset
75 function P_While_Statement (Loop_Name : Node_Id := Empty) return Node_Id;
kono
parents:
diff changeset
76 -- Parse while statement. If Loop_Name is non-Empty on entry, it is
kono
parents:
diff changeset
77 -- the N_Identifier node for the label on the loop. If Loop_Name is
kono
parents:
diff changeset
78 -- Empty on entry (the default), then the while statement is unlabeled.
kono
parents:
diff changeset
79
kono
parents:
diff changeset
80 function Set_Loop_Block_Name (L : Character) return Name_Id;
kono
parents:
diff changeset
81 -- Given a letter 'L' for a loop or 'B' for a block, returns a name
kono
parents:
diff changeset
82 -- of the form L_nn or B_nn where nn is a serial number obtained by
kono
parents:
diff changeset
83 -- incrementing the variable Loop_Block_Count.
kono
parents:
diff changeset
84
kono
parents:
diff changeset
85 procedure Then_Scan;
kono
parents:
diff changeset
86 -- Scan past THEN token, testing for illegal junk after it
kono
parents:
diff changeset
87
kono
parents:
diff changeset
88 ---------------------------------
kono
parents:
diff changeset
89 -- 5.1 Sequence of Statements --
kono
parents:
diff changeset
90 ---------------------------------
kono
parents:
diff changeset
91
kono
parents:
diff changeset
92 -- SEQUENCE_OF_STATEMENTS ::= STATEMENT {STATEMENT} {LABEL}
kono
parents:
diff changeset
93 -- Note: the final label is an Ada 2012 addition.
kono
parents:
diff changeset
94
kono
parents:
diff changeset
95 -- STATEMENT ::=
kono
parents:
diff changeset
96 -- {LABEL} SIMPLE_STATEMENT | {LABEL} COMPOUND_STATEMENT
kono
parents:
diff changeset
97
kono
parents:
diff changeset
98 -- SIMPLE_STATEMENT ::= NULL_STATEMENT
kono
parents:
diff changeset
99 -- | ASSIGNMENT_STATEMENT | EXIT_STATEMENT
kono
parents:
diff changeset
100 -- | GOTO_STATEMENT | PROCEDURE_CALL_STATEMENT
kono
parents:
diff changeset
101 -- | RETURN_STATEMENT | ENTRY_CALL_STATEMENT
kono
parents:
diff changeset
102 -- | REQUEUE_STATEMENT | DELAY_STATEMENT
kono
parents:
diff changeset
103 -- | ABORT_STATEMENT | RAISE_STATEMENT
kono
parents:
diff changeset
104 -- | CODE_STATEMENT
kono
parents:
diff changeset
105
kono
parents:
diff changeset
106 -- COMPOUND_STATEMENT ::=
kono
parents:
diff changeset
107 -- IF_STATEMENT | CASE_STATEMENT
kono
parents:
diff changeset
108 -- | LOOP_STATEMENT | BLOCK_STATEMENT
kono
parents:
diff changeset
109 -- | ACCEPT_STATEMENT | SELECT_STATEMENT
kono
parents:
diff changeset
110
kono
parents:
diff changeset
111 -- This procedure scans a sequence of statements. The caller sets SS_Flags
kono
parents:
diff changeset
112 -- to indicate acceptable termination conditions for the sequence:
kono
parents:
diff changeset
113
kono
parents:
diff changeset
114 -- SS_Flags.Eftm Terminate on ELSIF
kono
parents:
diff changeset
115 -- SS_Flags.Eltm Terminate on ELSE
kono
parents:
diff changeset
116 -- SS_Flags.Extm Terminate on EXCEPTION
kono
parents:
diff changeset
117 -- SS_Flags.Ortm Terminate on OR
kono
parents:
diff changeset
118 -- SS_Flags.Tatm Terminate on THEN ABORT (Token = ABORT on return)
kono
parents:
diff changeset
119 -- SS_Flags.Whtm Terminate on WHEN
kono
parents:
diff changeset
120 -- SS_Flags.Unco Unconditional terminate after scanning one statement
kono
parents:
diff changeset
121
kono
parents:
diff changeset
122 -- In addition, the scan is always terminated by encountering END or the
kono
parents:
diff changeset
123 -- end of file (EOF) condition. If one of the six above terminators is
kono
parents:
diff changeset
124 -- encountered with the corresponding SS_Flags flag not set, then the
kono
parents:
diff changeset
125 -- action taken is as follows:
kono
parents:
diff changeset
126
kono
parents:
diff changeset
127 -- If the keyword occurs to the left of the expected column of the end
kono
parents:
diff changeset
128 -- for the current sequence (as recorded in the current end context),
kono
parents:
diff changeset
129 -- then it is assumed to belong to an outer context, and is considered
kono
parents:
diff changeset
130 -- to terminate the sequence of statements.
kono
parents:
diff changeset
131
kono
parents:
diff changeset
132 -- If the keyword occurs to the right of, or in the expected column of
kono
parents:
diff changeset
133 -- the end for the current sequence, then an error message is output,
kono
parents:
diff changeset
134 -- the keyword together with its associated context is skipped, and
kono
parents:
diff changeset
135 -- the statement scan continues until another terminator is found.
kono
parents:
diff changeset
136
kono
parents:
diff changeset
137 -- Note that the first action means that control can return to the caller
kono
parents:
diff changeset
138 -- with Token set to a terminator other than one of those specified by the
kono
parents:
diff changeset
139 -- SS parameter. The caller should treat such a case as equivalent to END.
kono
parents:
diff changeset
140
kono
parents:
diff changeset
141 -- In addition, the flag SS_Flags.Sreq is set to True to indicate that at
kono
parents:
diff changeset
142 -- least one real statement (other than a pragma) is required in the
kono
parents:
diff changeset
143 -- statement sequence. During the processing of the sequence, this
kono
parents:
diff changeset
144 -- flag is manipulated to indicate the current status of the requirement
kono
parents:
diff changeset
145 -- for a statement. For example, it is turned off by the occurrence of a
kono
parents:
diff changeset
146 -- statement, and back on by a label (which requires a following statement)
kono
parents:
diff changeset
147
kono
parents:
diff changeset
148 -- Error recovery: cannot raise Error_Resync. If an error occurs during
kono
parents:
diff changeset
149 -- parsing a statement, then the scan pointer is advanced past the next
kono
parents:
diff changeset
150 -- semicolon and the parse continues.
kono
parents:
diff changeset
151
kono
parents:
diff changeset
152 function P_Sequence_Of_Statements (SS_Flags : SS_Rec) return List_Id is
kono
parents:
diff changeset
153
kono
parents:
diff changeset
154 Statement_Required : Boolean;
kono
parents:
diff changeset
155 -- This flag indicates if a subsequent statement (other than a pragma)
kono
parents:
diff changeset
156 -- is required. It is initialized from the Sreq flag, and modified as
kono
parents:
diff changeset
157 -- statements are scanned (a statement turns it off, and a label turns
kono
parents:
diff changeset
158 -- it back on again since a statement must follow a label).
kono
parents:
diff changeset
159 -- Note : this final requirement is lifted in Ada 2012.
kono
parents:
diff changeset
160
kono
parents:
diff changeset
161 Statement_Seen : Boolean;
kono
parents:
diff changeset
162 -- In Ada 2012, a label can end a sequence of statements, but the
kono
parents:
diff changeset
163 -- sequence cannot contain only labels. This flag is set whenever a
kono
parents:
diff changeset
164 -- label is encountered, to enforce this rule at the end of a sequence.
kono
parents:
diff changeset
165
kono
parents:
diff changeset
166 Declaration_Found : Boolean := False;
kono
parents:
diff changeset
167 -- This flag is set True if a declaration is encountered, so that the
kono
parents:
diff changeset
168 -- error message about declarations in the statement part is only
kono
parents:
diff changeset
169 -- given once for a given sequence of statements.
kono
parents:
diff changeset
170
kono
parents:
diff changeset
171 Scan_State_Label : Saved_Scan_State;
kono
parents:
diff changeset
172 Scan_State : Saved_Scan_State;
kono
parents:
diff changeset
173
kono
parents:
diff changeset
174 Statement_List : List_Id;
kono
parents:
diff changeset
175 Block_Label : Name_Id;
kono
parents:
diff changeset
176 Id_Node : Node_Id;
kono
parents:
diff changeset
177 Name_Node : Node_Id;
kono
parents:
diff changeset
178
kono
parents:
diff changeset
179 procedure Junk_Declaration;
kono
parents:
diff changeset
180 -- Procedure called to handle error of declaration encountered in
kono
parents:
diff changeset
181 -- statement sequence.
kono
parents:
diff changeset
182
kono
parents:
diff changeset
183 procedure Test_Statement_Required;
kono
parents:
diff changeset
184 -- Flag error if Statement_Required flag set
kono
parents:
diff changeset
185
kono
parents:
diff changeset
186 ----------------------
kono
parents:
diff changeset
187 -- Junk_Declaration --
kono
parents:
diff changeset
188 ----------------------
kono
parents:
diff changeset
189
kono
parents:
diff changeset
190 procedure Junk_Declaration is
kono
parents:
diff changeset
191 begin
kono
parents:
diff changeset
192 if (not Declaration_Found) or All_Errors_Mode then
kono
parents:
diff changeset
193 Error_Msg_SC -- CODEFIX
kono
parents:
diff changeset
194 ("declarations must come before BEGIN");
kono
parents:
diff changeset
195 Declaration_Found := True;
kono
parents:
diff changeset
196 end if;
kono
parents:
diff changeset
197
kono
parents:
diff changeset
198 Skip_Declaration (Statement_List);
kono
parents:
diff changeset
199 end Junk_Declaration;
kono
parents:
diff changeset
200
kono
parents:
diff changeset
201 -----------------------------
kono
parents:
diff changeset
202 -- Test_Statement_Required --
kono
parents:
diff changeset
203 -----------------------------
kono
parents:
diff changeset
204
kono
parents:
diff changeset
205 procedure Test_Statement_Required is
kono
parents:
diff changeset
206 function All_Pragmas return Boolean;
kono
parents:
diff changeset
207 -- Return True if statement list is all pragmas
kono
parents:
diff changeset
208
kono
parents:
diff changeset
209 -----------------
kono
parents:
diff changeset
210 -- All_Pragmas --
kono
parents:
diff changeset
211 -----------------
kono
parents:
diff changeset
212
kono
parents:
diff changeset
213 function All_Pragmas return Boolean is
kono
parents:
diff changeset
214 S : Node_Id;
kono
parents:
diff changeset
215 begin
kono
parents:
diff changeset
216 S := First (Statement_List);
kono
parents:
diff changeset
217 while Present (S) loop
kono
parents:
diff changeset
218 if Nkind (S) /= N_Pragma then
kono
parents:
diff changeset
219 return False;
kono
parents:
diff changeset
220 else
kono
parents:
diff changeset
221 Next (S);
kono
parents:
diff changeset
222 end if;
kono
parents:
diff changeset
223 end loop;
kono
parents:
diff changeset
224
kono
parents:
diff changeset
225 return True;
kono
parents:
diff changeset
226 end All_Pragmas;
kono
parents:
diff changeset
227
kono
parents:
diff changeset
228 -- Start of processing for Test_Statement_Required
kono
parents:
diff changeset
229
kono
parents:
diff changeset
230 begin
kono
parents:
diff changeset
231 if Statement_Required then
kono
parents:
diff changeset
232
kono
parents:
diff changeset
233 -- Check no statement required after label in Ada 2012, and that
kono
parents:
diff changeset
234 -- it is OK to have nothing but pragmas in a statement sequence.
kono
parents:
diff changeset
235
kono
parents:
diff changeset
236 if Ada_Version >= Ada_2012
kono
parents:
diff changeset
237 and then not Is_Empty_List (Statement_List)
kono
parents:
diff changeset
238 and then
kono
parents:
diff changeset
239 ((Nkind (Last (Statement_List)) = N_Label
kono
parents:
diff changeset
240 and then Statement_Seen)
kono
parents:
diff changeset
241 or else All_Pragmas)
kono
parents:
diff changeset
242 then
kono
parents:
diff changeset
243 -- This Ada 2012 construct not allowed in a compiler unit
kono
parents:
diff changeset
244
kono
parents:
diff changeset
245 Check_Compiler_Unit ("null statement list", Token_Ptr);
kono
parents:
diff changeset
246
kono
parents:
diff changeset
247 declare
kono
parents:
diff changeset
248 Null_Stm : constant Node_Id :=
kono
parents:
diff changeset
249 Make_Null_Statement (Token_Ptr);
kono
parents:
diff changeset
250 begin
kono
parents:
diff changeset
251 Set_Comes_From_Source (Null_Stm, False);
kono
parents:
diff changeset
252 Append_To (Statement_List, Null_Stm);
kono
parents:
diff changeset
253 end;
kono
parents:
diff changeset
254
kono
parents:
diff changeset
255 -- If not Ada 2012, or not special case above, give error message
kono
parents:
diff changeset
256
kono
parents:
diff changeset
257 else
kono
parents:
diff changeset
258 Error_Msg_BC -- CODEFIX
kono
parents:
diff changeset
259 ("statement expected");
kono
parents:
diff changeset
260 end if;
kono
parents:
diff changeset
261 end if;
kono
parents:
diff changeset
262 end Test_Statement_Required;
kono
parents:
diff changeset
263
kono
parents:
diff changeset
264 -- Start of processing for P_Sequence_Of_Statements
kono
parents:
diff changeset
265
kono
parents:
diff changeset
266 begin
kono
parents:
diff changeset
267 Statement_List := New_List;
kono
parents:
diff changeset
268 Statement_Required := SS_Flags.Sreq;
kono
parents:
diff changeset
269 Statement_Seen := False;
kono
parents:
diff changeset
270
kono
parents:
diff changeset
271 loop
kono
parents:
diff changeset
272 Ignore (Tok_Semicolon);
kono
parents:
diff changeset
273
kono
parents:
diff changeset
274 begin
kono
parents:
diff changeset
275 if Style_Check then
kono
parents:
diff changeset
276 Style.Check_Indentation;
kono
parents:
diff changeset
277 end if;
kono
parents:
diff changeset
278
kono
parents:
diff changeset
279 -- Deal with reserved identifier (in assignment or call)
kono
parents:
diff changeset
280
kono
parents:
diff changeset
281 if Is_Reserved_Identifier then
kono
parents:
diff changeset
282 Save_Scan_State (Scan_State); -- at possible bad identifier
kono
parents:
diff changeset
283 Scan; -- and scan past it
kono
parents:
diff changeset
284
kono
parents:
diff changeset
285 -- We have an reserved word which is spelled in identifier
kono
parents:
diff changeset
286 -- style, so the question is whether it really is intended
kono
parents:
diff changeset
287 -- to be an identifier.
kono
parents:
diff changeset
288
kono
parents:
diff changeset
289 if
kono
parents:
diff changeset
290 -- If followed by a semicolon, then it is an identifier,
kono
parents:
diff changeset
291 -- with the exception of the cases tested for below.
kono
parents:
diff changeset
292
kono
parents:
diff changeset
293 (Token = Tok_Semicolon
kono
parents:
diff changeset
294 and then Prev_Token /= Tok_Return
kono
parents:
diff changeset
295 and then Prev_Token /= Tok_Null
kono
parents:
diff changeset
296 and then Prev_Token /= Tok_Raise
kono
parents:
diff changeset
297 and then Prev_Token /= Tok_End
kono
parents:
diff changeset
298 and then Prev_Token /= Tok_Exit)
kono
parents:
diff changeset
299
kono
parents:
diff changeset
300 -- If followed by colon, colon-equal, or dot, then we
kono
parents:
diff changeset
301 -- definitely have an identifier (could not be reserved)
kono
parents:
diff changeset
302
kono
parents:
diff changeset
303 or else Token = Tok_Colon
kono
parents:
diff changeset
304 or else Token = Tok_Colon_Equal
kono
parents:
diff changeset
305 or else Token = Tok_Dot
kono
parents:
diff changeset
306
kono
parents:
diff changeset
307 -- Left paren means we have an identifier except for those
kono
parents:
diff changeset
308 -- reserved words that can legitimately be followed by a
kono
parents:
diff changeset
309 -- left paren.
kono
parents:
diff changeset
310
kono
parents:
diff changeset
311 or else
kono
parents:
diff changeset
312 (Token = Tok_Left_Paren
kono
parents:
diff changeset
313 and then Prev_Token /= Tok_Case
kono
parents:
diff changeset
314 and then Prev_Token /= Tok_Delay
kono
parents:
diff changeset
315 and then Prev_Token /= Tok_If
kono
parents:
diff changeset
316 and then Prev_Token /= Tok_Elsif
kono
parents:
diff changeset
317 and then Prev_Token /= Tok_Return
kono
parents:
diff changeset
318 and then Prev_Token /= Tok_When
kono
parents:
diff changeset
319 and then Prev_Token /= Tok_While
kono
parents:
diff changeset
320 and then Prev_Token /= Tok_Separate)
kono
parents:
diff changeset
321 then
kono
parents:
diff changeset
322 -- Here we have an apparent reserved identifier and the
kono
parents:
diff changeset
323 -- token past it is appropriate to this usage (and would
kono
parents:
diff changeset
324 -- be a definite error if this is not an identifier). What
kono
parents:
diff changeset
325 -- we do is to use P_Identifier to fix up the identifier,
kono
parents:
diff changeset
326 -- and then fall into the normal processing.
kono
parents:
diff changeset
327
kono
parents:
diff changeset
328 Restore_Scan_State (Scan_State); -- back to the ID
kono
parents:
diff changeset
329 Scan_Reserved_Identifier (Force_Msg => False);
kono
parents:
diff changeset
330
kono
parents:
diff changeset
331 -- Not a reserved identifier after all (or at least we can't
kono
parents:
diff changeset
332 -- be sure that it is), so reset the scan and continue.
kono
parents:
diff changeset
333
kono
parents:
diff changeset
334 else
kono
parents:
diff changeset
335 Restore_Scan_State (Scan_State); -- back to the reserved word
kono
parents:
diff changeset
336 end if;
kono
parents:
diff changeset
337 end if;
kono
parents:
diff changeset
338
kono
parents:
diff changeset
339 -- Now look to see what kind of statement we have
kono
parents:
diff changeset
340
kono
parents:
diff changeset
341 case Token is
kono
parents:
diff changeset
342
kono
parents:
diff changeset
343 -- Case of end or EOF
kono
parents:
diff changeset
344
kono
parents:
diff changeset
345 when Tok_End
kono
parents:
diff changeset
346 | Tok_EOF
kono
parents:
diff changeset
347 =>
kono
parents:
diff changeset
348 -- These tokens always terminate the statement sequence
kono
parents:
diff changeset
349
kono
parents:
diff changeset
350 Test_Statement_Required;
kono
parents:
diff changeset
351 exit;
kono
parents:
diff changeset
352
kono
parents:
diff changeset
353 -- Case of ELSIF
kono
parents:
diff changeset
354
kono
parents:
diff changeset
355 when Tok_Elsif =>
kono
parents:
diff changeset
356
kono
parents:
diff changeset
357 -- Terminate if Eftm set or if the ELSIF is to the left
kono
parents:
diff changeset
358 -- of the expected column of the end for this sequence
kono
parents:
diff changeset
359
kono
parents:
diff changeset
360 if SS_Flags.Eftm
kono
parents:
diff changeset
361 or else Start_Column < Scope.Table (Scope.Last).Ecol
kono
parents:
diff changeset
362 then
kono
parents:
diff changeset
363 Test_Statement_Required;
kono
parents:
diff changeset
364 exit;
kono
parents:
diff changeset
365
kono
parents:
diff changeset
366 -- Otherwise complain and skip past ELSIF Condition then
kono
parents:
diff changeset
367
kono
parents:
diff changeset
368 else
kono
parents:
diff changeset
369 Error_Msg_SC ("ELSIF not allowed here");
kono
parents:
diff changeset
370 Scan; -- past ELSIF
kono
parents:
diff changeset
371 Discard_Junk_Node (P_Expression_No_Right_Paren);
kono
parents:
diff changeset
372 Then_Scan;
kono
parents:
diff changeset
373 Statement_Required := False;
kono
parents:
diff changeset
374 end if;
kono
parents:
diff changeset
375
kono
parents:
diff changeset
376 -- Case of ELSE
kono
parents:
diff changeset
377
kono
parents:
diff changeset
378 when Tok_Else =>
kono
parents:
diff changeset
379
kono
parents:
diff changeset
380 -- Terminate if Eltm set or if the else is to the left
kono
parents:
diff changeset
381 -- of the expected column of the end for this sequence
kono
parents:
diff changeset
382
kono
parents:
diff changeset
383 if SS_Flags.Eltm
kono
parents:
diff changeset
384 or else Start_Column < Scope.Table (Scope.Last).Ecol
kono
parents:
diff changeset
385 then
kono
parents:
diff changeset
386 Test_Statement_Required;
kono
parents:
diff changeset
387 exit;
kono
parents:
diff changeset
388
kono
parents:
diff changeset
389 -- Otherwise complain and skip past else
kono
parents:
diff changeset
390
kono
parents:
diff changeset
391 else
kono
parents:
diff changeset
392 Error_Msg_SC ("ELSE not allowed here");
kono
parents:
diff changeset
393 Scan; -- past ELSE
kono
parents:
diff changeset
394 Statement_Required := False;
kono
parents:
diff changeset
395 end if;
kono
parents:
diff changeset
396
kono
parents:
diff changeset
397 -- Case of exception
kono
parents:
diff changeset
398
kono
parents:
diff changeset
399 when Tok_Exception =>
kono
parents:
diff changeset
400 Test_Statement_Required;
kono
parents:
diff changeset
401
kono
parents:
diff changeset
402 -- If Extm not set and the exception is not to the left of
kono
parents:
diff changeset
403 -- the expected column of the end for this sequence, then we
kono
parents:
diff changeset
404 -- assume it belongs to the current sequence, even though it
kono
parents:
diff changeset
405 -- is not permitted.
kono
parents:
diff changeset
406
kono
parents:
diff changeset
407 if not SS_Flags.Extm and then
kono
parents:
diff changeset
408 Start_Column >= Scope.Table (Scope.Last).Ecol
kono
parents:
diff changeset
409
kono
parents:
diff changeset
410 then
kono
parents:
diff changeset
411 Error_Msg_SC ("exception handler not permitted here");
kono
parents:
diff changeset
412 Scan; -- past EXCEPTION
kono
parents:
diff changeset
413 Discard_Junk_List (Parse_Exception_Handlers);
kono
parents:
diff changeset
414 end if;
kono
parents:
diff changeset
415
kono
parents:
diff changeset
416 -- Always return, in the case where we scanned out handlers
kono
parents:
diff changeset
417 -- that we did not expect, Parse_Exception_Handlers returned
kono
parents:
diff changeset
418 -- with Token being either end or EOF, so we are OK.
kono
parents:
diff changeset
419
kono
parents:
diff changeset
420 exit;
kono
parents:
diff changeset
421
kono
parents:
diff changeset
422 -- Case of OR
kono
parents:
diff changeset
423
kono
parents:
diff changeset
424 when Tok_Or =>
kono
parents:
diff changeset
425
kono
parents:
diff changeset
426 -- Terminate if Ortm set or if the or is to the left of the
kono
parents:
diff changeset
427 -- expected column of the end for this sequence.
kono
parents:
diff changeset
428
kono
parents:
diff changeset
429 if SS_Flags.Ortm
kono
parents:
diff changeset
430 or else Start_Column < Scope.Table (Scope.Last).Ecol
kono
parents:
diff changeset
431 then
kono
parents:
diff changeset
432 Test_Statement_Required;
kono
parents:
diff changeset
433 exit;
kono
parents:
diff changeset
434
kono
parents:
diff changeset
435 -- Otherwise complain and skip past or
kono
parents:
diff changeset
436
kono
parents:
diff changeset
437 else
kono
parents:
diff changeset
438 Error_Msg_SC ("OR not allowed here");
kono
parents:
diff changeset
439 Scan; -- past or
kono
parents:
diff changeset
440 Statement_Required := False;
kono
parents:
diff changeset
441 end if;
kono
parents:
diff changeset
442
kono
parents:
diff changeset
443 -- Case of THEN (deal also with THEN ABORT)
kono
parents:
diff changeset
444
kono
parents:
diff changeset
445 when Tok_Then =>
kono
parents:
diff changeset
446 Save_Scan_State (Scan_State); -- at THEN
kono
parents:
diff changeset
447 Scan; -- past THEN
kono
parents:
diff changeset
448
kono
parents:
diff changeset
449 -- Terminate if THEN ABORT allowed (ATC case)
kono
parents:
diff changeset
450
kono
parents:
diff changeset
451 exit when SS_Flags.Tatm and then Token = Tok_Abort;
kono
parents:
diff changeset
452
kono
parents:
diff changeset
453 -- Otherwise we treat THEN as some kind of mess where we did
kono
parents:
diff changeset
454 -- not see the associated IF, but we pick up assuming it had
kono
parents:
diff changeset
455 -- been there.
kono
parents:
diff changeset
456
kono
parents:
diff changeset
457 Restore_Scan_State (Scan_State); -- to THEN
kono
parents:
diff changeset
458 Append_To (Statement_List, P_If_Statement);
kono
parents:
diff changeset
459 Statement_Required := False;
kono
parents:
diff changeset
460
kono
parents:
diff changeset
461 -- Case of WHEN (error because we are not in a case)
kono
parents:
diff changeset
462
kono
parents:
diff changeset
463 when Tok_Others
kono
parents:
diff changeset
464 | Tok_When
kono
parents:
diff changeset
465 =>
kono
parents:
diff changeset
466 -- Terminate if Whtm set or if the WHEN is to the left of
kono
parents:
diff changeset
467 -- the expected column of the end for this sequence.
kono
parents:
diff changeset
468
kono
parents:
diff changeset
469 if SS_Flags.Whtm
kono
parents:
diff changeset
470 or else Start_Column < Scope.Table (Scope.Last).Ecol
kono
parents:
diff changeset
471 then
kono
parents:
diff changeset
472 Test_Statement_Required;
kono
parents:
diff changeset
473 exit;
kono
parents:
diff changeset
474
kono
parents:
diff changeset
475 -- Otherwise complain and skip when Choice {| Choice} =>
kono
parents:
diff changeset
476
kono
parents:
diff changeset
477 else
kono
parents:
diff changeset
478 Error_Msg_SC ("WHEN not allowed here");
kono
parents:
diff changeset
479 Scan; -- past when
kono
parents:
diff changeset
480 Discard_Junk_List (P_Discrete_Choice_List);
kono
parents:
diff changeset
481 TF_Arrow;
kono
parents:
diff changeset
482 Statement_Required := False;
kono
parents:
diff changeset
483 end if;
kono
parents:
diff changeset
484
kono
parents:
diff changeset
485 -- Cases of statements starting with an identifier
kono
parents:
diff changeset
486
kono
parents:
diff changeset
487 when Tok_Identifier =>
kono
parents:
diff changeset
488 Check_Bad_Layout;
kono
parents:
diff changeset
489
kono
parents:
diff changeset
490 -- Save scan pointers and line number in case block label
kono
parents:
diff changeset
491
kono
parents:
diff changeset
492 Id_Node := Token_Node;
kono
parents:
diff changeset
493 Block_Label := Token_Name;
kono
parents:
diff changeset
494 Save_Scan_State (Scan_State_Label); -- at possible label
kono
parents:
diff changeset
495 Scan; -- past Id
kono
parents:
diff changeset
496
kono
parents:
diff changeset
497 -- Check for common case of assignment, since it occurs
kono
parents:
diff changeset
498 -- frequently, and we want to process it efficiently.
kono
parents:
diff changeset
499
kono
parents:
diff changeset
500 if Token = Tok_Colon_Equal then
kono
parents:
diff changeset
501 Scan; -- past the colon-equal
kono
parents:
diff changeset
502 Append_To (Statement_List,
kono
parents:
diff changeset
503 P_Assignment_Statement (Id_Node));
kono
parents:
diff changeset
504 Statement_Required := False;
kono
parents:
diff changeset
505
kono
parents:
diff changeset
506 -- Check common case of procedure call, another case that
kono
parents:
diff changeset
507 -- we want to speed up as much as possible.
kono
parents:
diff changeset
508
kono
parents:
diff changeset
509 elsif Token = Tok_Semicolon then
kono
parents:
diff changeset
510 Change_Name_To_Procedure_Call_Statement (Id_Node);
kono
parents:
diff changeset
511 Append_To (Statement_List, Id_Node);
kono
parents:
diff changeset
512 Scan; -- past semicolon
kono
parents:
diff changeset
513 Statement_Required := False;
kono
parents:
diff changeset
514
kono
parents:
diff changeset
515 -- Here is the special test for a suspicious label, more
kono
parents:
diff changeset
516 -- accurately a suspicious name, which we think perhaps
kono
parents:
diff changeset
517 -- should have been a label. If next token is one of
kono
parents:
diff changeset
518 -- LOOP, FOR, WHILE, DECLARE, BEGIN, then make an entry
kono
parents:
diff changeset
519 -- in the suspicious label table.
kono
parents:
diff changeset
520
kono
parents:
diff changeset
521 if Token = Tok_Loop or else
kono
parents:
diff changeset
522 Token = Tok_For or else
kono
parents:
diff changeset
523 Token = Tok_While or else
kono
parents:
diff changeset
524 Token = Tok_Declare or else
kono
parents:
diff changeset
525 Token = Tok_Begin
kono
parents:
diff changeset
526 then
kono
parents:
diff changeset
527 Suspicious_Labels.Append
kono
parents:
diff changeset
528 ((Proc_Call => Id_Node,
kono
parents:
diff changeset
529 Semicolon_Loc => Prev_Token_Ptr,
kono
parents:
diff changeset
530 Start_Token => Token_Ptr));
kono
parents:
diff changeset
531 end if;
kono
parents:
diff changeset
532
kono
parents:
diff changeset
533 -- Check for case of "go to" in place of "goto"
kono
parents:
diff changeset
534
kono
parents:
diff changeset
535 elsif Token = Tok_Identifier
kono
parents:
diff changeset
536 and then Block_Label = Name_Go
kono
parents:
diff changeset
537 and then Token_Name = Name_To
kono
parents:
diff changeset
538 then
kono
parents:
diff changeset
539 Error_Msg_SP -- CODEFIX
kono
parents:
diff changeset
540 ("goto is one word");
kono
parents:
diff changeset
541 Append_To (Statement_List, P_Goto_Statement);
kono
parents:
diff changeset
542 Statement_Required := False;
kono
parents:
diff changeset
543
kono
parents:
diff changeset
544 -- Check common case of = used instead of :=, just so we
kono
parents:
diff changeset
545 -- give a better error message for this special misuse.
kono
parents:
diff changeset
546
kono
parents:
diff changeset
547 elsif Token = Tok_Equal then
kono
parents:
diff changeset
548 T_Colon_Equal; -- give := expected message
kono
parents:
diff changeset
549 Append_To (Statement_List,
kono
parents:
diff changeset
550 P_Assignment_Statement (Id_Node));
kono
parents:
diff changeset
551 Statement_Required := False;
kono
parents:
diff changeset
552
kono
parents:
diff changeset
553 -- Check case of loop label or block label
kono
parents:
diff changeset
554
kono
parents:
diff changeset
555 elsif Token = Tok_Colon
kono
parents:
diff changeset
556 or else (Token in Token_Class_Labeled_Stmt
kono
parents:
diff changeset
557 and then not Token_Is_At_Start_Of_Line)
kono
parents:
diff changeset
558 then
kono
parents:
diff changeset
559 T_Colon; -- past colon (if there, or msg for missing one)
kono
parents:
diff changeset
560
kono
parents:
diff changeset
561 -- Test for more than one label
kono
parents:
diff changeset
562
kono
parents:
diff changeset
563 loop
kono
parents:
diff changeset
564 exit when Token /= Tok_Identifier;
kono
parents:
diff changeset
565 Save_Scan_State (Scan_State); -- at second Id
kono
parents:
diff changeset
566 Scan; -- past Id
kono
parents:
diff changeset
567
kono
parents:
diff changeset
568 if Token = Tok_Colon then
kono
parents:
diff changeset
569 Error_Msg_SP
kono
parents:
diff changeset
570 ("only one label allowed on block or loop");
kono
parents:
diff changeset
571 Scan; -- past colon on extra label
kono
parents:
diff changeset
572
kono
parents:
diff changeset
573 -- Use the second label as the "real" label
kono
parents:
diff changeset
574
kono
parents:
diff changeset
575 Scan_State_Label := Scan_State;
kono
parents:
diff changeset
576
kono
parents:
diff changeset
577 -- We will set Error_name as the Block_Label since
kono
parents:
diff changeset
578 -- we really don't know which of the labels might
kono
parents:
diff changeset
579 -- be used at the end of the loop or block.
kono
parents:
diff changeset
580
kono
parents:
diff changeset
581 Block_Label := Error_Name;
kono
parents:
diff changeset
582
kono
parents:
diff changeset
583 -- If Id with no colon, then backup to point to the
kono
parents:
diff changeset
584 -- Id and we will issue the message below when we try
kono
parents:
diff changeset
585 -- to scan out the statement as some other form.
kono
parents:
diff changeset
586
kono
parents:
diff changeset
587 else
kono
parents:
diff changeset
588 Restore_Scan_State (Scan_State); -- to second Id
kono
parents:
diff changeset
589 exit;
kono
parents:
diff changeset
590 end if;
kono
parents:
diff changeset
591 end loop;
kono
parents:
diff changeset
592
kono
parents:
diff changeset
593 -- Loop_Statement (labeled Loop_Statement)
kono
parents:
diff changeset
594
kono
parents:
diff changeset
595 if Token = Tok_Loop then
kono
parents:
diff changeset
596 Append_To (Statement_List,
kono
parents:
diff changeset
597 P_Loop_Statement (Id_Node));
kono
parents:
diff changeset
598
kono
parents:
diff changeset
599 -- While statement (labeled loop statement with WHILE)
kono
parents:
diff changeset
600
kono
parents:
diff changeset
601 elsif Token = Tok_While then
kono
parents:
diff changeset
602 Append_To (Statement_List,
kono
parents:
diff changeset
603 P_While_Statement (Id_Node));
kono
parents:
diff changeset
604
kono
parents:
diff changeset
605 -- Declare statement (labeled block statement with
kono
parents:
diff changeset
606 -- DECLARE part)
kono
parents:
diff changeset
607
kono
parents:
diff changeset
608 elsif Token = Tok_Declare then
kono
parents:
diff changeset
609 Append_To (Statement_List,
kono
parents:
diff changeset
610 P_Declare_Statement (Id_Node));
kono
parents:
diff changeset
611
kono
parents:
diff changeset
612 -- Begin statement (labeled block statement with no
kono
parents:
diff changeset
613 -- DECLARE part)
kono
parents:
diff changeset
614
kono
parents:
diff changeset
615 elsif Token = Tok_Begin then
kono
parents:
diff changeset
616 Append_To (Statement_List,
kono
parents:
diff changeset
617 P_Begin_Statement (Id_Node));
kono
parents:
diff changeset
618
kono
parents:
diff changeset
619 -- For statement (labeled loop statement with FOR)
kono
parents:
diff changeset
620
kono
parents:
diff changeset
621 elsif Token = Tok_For then
kono
parents:
diff changeset
622 Append_To (Statement_List,
kono
parents:
diff changeset
623 P_For_Statement (Id_Node));
kono
parents:
diff changeset
624
kono
parents:
diff changeset
625 -- Improper statement follows label. If we have an
kono
parents:
diff changeset
626 -- expression token, then assume the colon was part
kono
parents:
diff changeset
627 -- of a misplaced declaration.
kono
parents:
diff changeset
628
kono
parents:
diff changeset
629 elsif Token not in Token_Class_Eterm then
kono
parents:
diff changeset
630 Restore_Scan_State (Scan_State_Label);
kono
parents:
diff changeset
631 Junk_Declaration;
kono
parents:
diff changeset
632
kono
parents:
diff changeset
633 -- Otherwise complain we have inappropriate statement
kono
parents:
diff changeset
634
kono
parents:
diff changeset
635 else
kono
parents:
diff changeset
636 Error_Msg_AP
kono
parents:
diff changeset
637 ("loop or block statement must follow label");
kono
parents:
diff changeset
638 end if;
kono
parents:
diff changeset
639
kono
parents:
diff changeset
640 Statement_Required := False;
kono
parents:
diff changeset
641
kono
parents:
diff changeset
642 -- Here we have an identifier followed by something
kono
parents:
diff changeset
643 -- other than a colon, semicolon or assignment symbol.
kono
parents:
diff changeset
644 -- The only valid possibility is a name extension symbol
kono
parents:
diff changeset
645
kono
parents:
diff changeset
646 elsif Token in Token_Class_Namext then
kono
parents:
diff changeset
647 Restore_Scan_State (Scan_State_Label); -- to Id
kono
parents:
diff changeset
648 Name_Node := P_Name;
kono
parents:
diff changeset
649
kono
parents:
diff changeset
650 -- Skip junk right parens in this context
kono
parents:
diff changeset
651
kono
parents:
diff changeset
652 Ignore (Tok_Right_Paren);
kono
parents:
diff changeset
653
kono
parents:
diff changeset
654 -- Check context following call
kono
parents:
diff changeset
655
kono
parents:
diff changeset
656 if Token = Tok_Colon_Equal then
kono
parents:
diff changeset
657 Scan; -- past colon equal
kono
parents:
diff changeset
658 Append_To (Statement_List,
kono
parents:
diff changeset
659 P_Assignment_Statement (Name_Node));
kono
parents:
diff changeset
660 Statement_Required := False;
kono
parents:
diff changeset
661
kono
parents:
diff changeset
662 -- Check common case of = used instead of :=
kono
parents:
diff changeset
663
kono
parents:
diff changeset
664 elsif Token = Tok_Equal then
kono
parents:
diff changeset
665 T_Colon_Equal; -- give := expected message
kono
parents:
diff changeset
666 Append_To (Statement_List,
kono
parents:
diff changeset
667 P_Assignment_Statement (Name_Node));
kono
parents:
diff changeset
668 Statement_Required := False;
kono
parents:
diff changeset
669
kono
parents:
diff changeset
670 -- Check apostrophe cases
kono
parents:
diff changeset
671
kono
parents:
diff changeset
672 elsif Token = Tok_Apostrophe then
kono
parents:
diff changeset
673 Append_To (Statement_List,
kono
parents:
diff changeset
674 P_Code_Statement (Name_Node));
kono
parents:
diff changeset
675 Statement_Required := False;
kono
parents:
diff changeset
676
kono
parents:
diff changeset
677 -- The only other valid item after a name is ; which
kono
parents:
diff changeset
678 -- means that the item we just scanned was a call.
kono
parents:
diff changeset
679
kono
parents:
diff changeset
680 elsif Token = Tok_Semicolon then
kono
parents:
diff changeset
681 Change_Name_To_Procedure_Call_Statement (Name_Node);
kono
parents:
diff changeset
682 Append_To (Statement_List, Name_Node);
kono
parents:
diff changeset
683 Scan; -- past semicolon
kono
parents:
diff changeset
684 Statement_Required := False;
kono
parents:
diff changeset
685
kono
parents:
diff changeset
686 -- A slash following an identifier or a selected
kono
parents:
diff changeset
687 -- component in this situation is most likely a period
kono
parents:
diff changeset
688 -- (see location of keys on keyboard).
kono
parents:
diff changeset
689
kono
parents:
diff changeset
690 elsif Token = Tok_Slash
kono
parents:
diff changeset
691 and then (Nkind (Name_Node) = N_Identifier
kono
parents:
diff changeset
692 or else
kono
parents:
diff changeset
693 Nkind (Name_Node) = N_Selected_Component)
kono
parents:
diff changeset
694 then
kono
parents:
diff changeset
695 Error_Msg_SC -- CODEFIX
kono
parents:
diff changeset
696 ("""/"" should be "".""");
kono
parents:
diff changeset
697 Statement_Required := False;
kono
parents:
diff changeset
698 raise Error_Resync;
kono
parents:
diff changeset
699
kono
parents:
diff changeset
700 -- Else we have a missing semicolon
kono
parents:
diff changeset
701
kono
parents:
diff changeset
702 else
kono
parents:
diff changeset
703 TF_Semicolon;
kono
parents:
diff changeset
704
kono
parents:
diff changeset
705 -- Normal processing as though semicolon were present
kono
parents:
diff changeset
706
kono
parents:
diff changeset
707 Change_Name_To_Procedure_Call_Statement (Name_Node);
kono
parents:
diff changeset
708 Append_To (Statement_List, Name_Node);
kono
parents:
diff changeset
709 Statement_Required := False;
kono
parents:
diff changeset
710 end if;
kono
parents:
diff changeset
711
kono
parents:
diff changeset
712 -- If junk after identifier, check if identifier is an
kono
parents:
diff changeset
713 -- instance of an incorrectly spelled keyword. If so, we
kono
parents:
diff changeset
714 -- do nothing. The Bad_Spelling_Of will have reset Token
kono
parents:
diff changeset
715 -- to the appropriate keyword, so the next time round the
kono
parents:
diff changeset
716 -- loop we will process the modified token. Note that we
kono
parents:
diff changeset
717 -- check for ELSIF before ELSE here. That's not accidental.
kono
parents:
diff changeset
718 -- We don't want to identify a misspelling of ELSE as
kono
parents:
diff changeset
719 -- ELSIF, and in particular we do not want to treat ELSEIF
kono
parents:
diff changeset
720 -- as ELSE IF.
kono
parents:
diff changeset
721
kono
parents:
diff changeset
722 else
kono
parents:
diff changeset
723 Restore_Scan_State (Scan_State_Label); -- to identifier
kono
parents:
diff changeset
724
kono
parents:
diff changeset
725 if Bad_Spelling_Of (Tok_Abort)
kono
parents:
diff changeset
726 or else Bad_Spelling_Of (Tok_Accept)
kono
parents:
diff changeset
727 or else Bad_Spelling_Of (Tok_Case)
kono
parents:
diff changeset
728 or else Bad_Spelling_Of (Tok_Declare)
kono
parents:
diff changeset
729 or else Bad_Spelling_Of (Tok_Delay)
kono
parents:
diff changeset
730 or else Bad_Spelling_Of (Tok_Elsif)
kono
parents:
diff changeset
731 or else Bad_Spelling_Of (Tok_Else)
kono
parents:
diff changeset
732 or else Bad_Spelling_Of (Tok_End)
kono
parents:
diff changeset
733 or else Bad_Spelling_Of (Tok_Exception)
kono
parents:
diff changeset
734 or else Bad_Spelling_Of (Tok_Exit)
kono
parents:
diff changeset
735 or else Bad_Spelling_Of (Tok_For)
kono
parents:
diff changeset
736 or else Bad_Spelling_Of (Tok_Goto)
kono
parents:
diff changeset
737 or else Bad_Spelling_Of (Tok_If)
kono
parents:
diff changeset
738 or else Bad_Spelling_Of (Tok_Loop)
kono
parents:
diff changeset
739 or else Bad_Spelling_Of (Tok_Or)
kono
parents:
diff changeset
740 or else Bad_Spelling_Of (Tok_Pragma)
kono
parents:
diff changeset
741 or else Bad_Spelling_Of (Tok_Raise)
kono
parents:
diff changeset
742 or else Bad_Spelling_Of (Tok_Requeue)
kono
parents:
diff changeset
743 or else Bad_Spelling_Of (Tok_Return)
kono
parents:
diff changeset
744 or else Bad_Spelling_Of (Tok_Select)
kono
parents:
diff changeset
745 or else Bad_Spelling_Of (Tok_When)
kono
parents:
diff changeset
746 or else Bad_Spelling_Of (Tok_While)
kono
parents:
diff changeset
747 then
kono
parents:
diff changeset
748 null;
kono
parents:
diff changeset
749
kono
parents:
diff changeset
750 -- If not a bad spelling, then we really have junk
kono
parents:
diff changeset
751
kono
parents:
diff changeset
752 else
kono
parents:
diff changeset
753 Scan; -- past identifier again
kono
parents:
diff changeset
754
kono
parents:
diff changeset
755 -- If next token is first token on line, then we
kono
parents:
diff changeset
756 -- consider that we were missing a semicolon after
kono
parents:
diff changeset
757 -- the identifier, and process it as a procedure
kono
parents:
diff changeset
758 -- call with no parameters.
kono
parents:
diff changeset
759
kono
parents:
diff changeset
760 if Token_Is_At_Start_Of_Line then
kono
parents:
diff changeset
761 Change_Name_To_Procedure_Call_Statement (Id_Node);
kono
parents:
diff changeset
762 Append_To (Statement_List, Id_Node);
kono
parents:
diff changeset
763 T_Semicolon; -- to give error message
kono
parents:
diff changeset
764 Statement_Required := False;
kono
parents:
diff changeset
765
kono
parents:
diff changeset
766 -- Otherwise we give a missing := message and
kono
parents:
diff changeset
767 -- simply abandon the junk that is there now.
kono
parents:
diff changeset
768
kono
parents:
diff changeset
769 else
kono
parents:
diff changeset
770 T_Colon_Equal; -- give := expected message
kono
parents:
diff changeset
771 raise Error_Resync;
kono
parents:
diff changeset
772 end if;
kono
parents:
diff changeset
773
kono
parents:
diff changeset
774 end if;
kono
parents:
diff changeset
775 end if;
kono
parents:
diff changeset
776
kono
parents:
diff changeset
777 -- Statement starting with operator symbol. This could be
kono
parents:
diff changeset
778 -- a call, a name starting an assignment, or a qualified
kono
parents:
diff changeset
779 -- expression.
kono
parents:
diff changeset
780
kono
parents:
diff changeset
781 when Tok_Operator_Symbol =>
kono
parents:
diff changeset
782 Check_Bad_Layout;
kono
parents:
diff changeset
783 Name_Node := P_Name;
kono
parents:
diff changeset
784
kono
parents:
diff changeset
785 -- An attempt at a range attribute or a qualified expression
kono
parents:
diff changeset
786 -- must be illegal here (a code statement cannot possibly
kono
parents:
diff changeset
787 -- allow qualification by a function name).
kono
parents:
diff changeset
788
kono
parents:
diff changeset
789 if Token = Tok_Apostrophe then
kono
parents:
diff changeset
790 Error_Msg_SC ("apostrophe illegal here");
kono
parents:
diff changeset
791 raise Error_Resync;
kono
parents:
diff changeset
792 end if;
kono
parents:
diff changeset
793
kono
parents:
diff changeset
794 -- Scan possible assignment if we have a name
kono
parents:
diff changeset
795
kono
parents:
diff changeset
796 if Expr_Form = EF_Name
kono
parents:
diff changeset
797 and then Token = Tok_Colon_Equal
kono
parents:
diff changeset
798 then
kono
parents:
diff changeset
799 Scan; -- past colon equal
kono
parents:
diff changeset
800 Append_To (Statement_List,
kono
parents:
diff changeset
801 P_Assignment_Statement (Name_Node));
kono
parents:
diff changeset
802 else
kono
parents:
diff changeset
803 Change_Name_To_Procedure_Call_Statement (Name_Node);
kono
parents:
diff changeset
804 Append_To (Statement_List, Name_Node);
kono
parents:
diff changeset
805 end if;
kono
parents:
diff changeset
806
kono
parents:
diff changeset
807 TF_Semicolon;
kono
parents:
diff changeset
808 Statement_Required := False;
kono
parents:
diff changeset
809
kono
parents:
diff changeset
810 -- Label starting with << which must precede real statement
kono
parents:
diff changeset
811 -- Note: in Ada 2012, the label may end the sequence.
kono
parents:
diff changeset
812
kono
parents:
diff changeset
813 when Tok_Less_Less =>
kono
parents:
diff changeset
814 if Present (Last (Statement_List))
kono
parents:
diff changeset
815 and then Nkind (Last (Statement_List)) /= N_Label
kono
parents:
diff changeset
816 then
kono
parents:
diff changeset
817 Statement_Seen := True;
kono
parents:
diff changeset
818 end if;
kono
parents:
diff changeset
819
kono
parents:
diff changeset
820 Append_To (Statement_List, P_Label);
kono
parents:
diff changeset
821 Statement_Required := True;
kono
parents:
diff changeset
822
kono
parents:
diff changeset
823 -- Pragma appearing as a statement in a statement sequence
kono
parents:
diff changeset
824
kono
parents:
diff changeset
825 when Tok_Pragma =>
kono
parents:
diff changeset
826 Check_Bad_Layout;
kono
parents:
diff changeset
827 Append_To (Statement_List, P_Pragma);
kono
parents:
diff changeset
828
kono
parents:
diff changeset
829 -- Abort_Statement
kono
parents:
diff changeset
830
kono
parents:
diff changeset
831 when Tok_Abort =>
kono
parents:
diff changeset
832 Check_Bad_Layout;
kono
parents:
diff changeset
833 Append_To (Statement_List, P_Abort_Statement);
kono
parents:
diff changeset
834 Statement_Required := False;
kono
parents:
diff changeset
835
kono
parents:
diff changeset
836 -- Accept_Statement
kono
parents:
diff changeset
837
kono
parents:
diff changeset
838 when Tok_Accept =>
kono
parents:
diff changeset
839 Check_Bad_Layout;
kono
parents:
diff changeset
840 Append_To (Statement_List, P_Accept_Statement);
kono
parents:
diff changeset
841 Statement_Required := False;
kono
parents:
diff changeset
842
kono
parents:
diff changeset
843 -- Begin_Statement (Block_Statement with no declare, no label)
kono
parents:
diff changeset
844
kono
parents:
diff changeset
845 when Tok_Begin =>
kono
parents:
diff changeset
846 Check_Bad_Layout;
kono
parents:
diff changeset
847 Append_To (Statement_List, P_Begin_Statement);
kono
parents:
diff changeset
848 Statement_Required := False;
kono
parents:
diff changeset
849
kono
parents:
diff changeset
850 -- Case_Statement
kono
parents:
diff changeset
851
kono
parents:
diff changeset
852 when Tok_Case =>
kono
parents:
diff changeset
853 Check_Bad_Layout;
kono
parents:
diff changeset
854 Append_To (Statement_List, P_Case_Statement);
kono
parents:
diff changeset
855 Statement_Required := False;
kono
parents:
diff changeset
856
kono
parents:
diff changeset
857 -- Block_Statement with DECLARE and no label
kono
parents:
diff changeset
858
kono
parents:
diff changeset
859 when Tok_Declare =>
kono
parents:
diff changeset
860 Check_Bad_Layout;
kono
parents:
diff changeset
861 Append_To (Statement_List, P_Declare_Statement);
kono
parents:
diff changeset
862 Statement_Required := False;
kono
parents:
diff changeset
863
kono
parents:
diff changeset
864 -- Delay_Statement
kono
parents:
diff changeset
865
kono
parents:
diff changeset
866 when Tok_Delay =>
kono
parents:
diff changeset
867 Check_Bad_Layout;
kono
parents:
diff changeset
868 Append_To (Statement_List, P_Delay_Statement);
kono
parents:
diff changeset
869 Statement_Required := False;
kono
parents:
diff changeset
870
kono
parents:
diff changeset
871 -- Exit_Statement
kono
parents:
diff changeset
872
kono
parents:
diff changeset
873 when Tok_Exit =>
kono
parents:
diff changeset
874 Check_Bad_Layout;
kono
parents:
diff changeset
875 Append_To (Statement_List, P_Exit_Statement);
kono
parents:
diff changeset
876 Statement_Required := False;
kono
parents:
diff changeset
877
kono
parents:
diff changeset
878 -- Loop_Statement with FOR and no label
kono
parents:
diff changeset
879
kono
parents:
diff changeset
880 when Tok_For =>
kono
parents:
diff changeset
881 Check_Bad_Layout;
kono
parents:
diff changeset
882 Append_To (Statement_List, P_For_Statement);
kono
parents:
diff changeset
883 Statement_Required := False;
kono
parents:
diff changeset
884
kono
parents:
diff changeset
885 -- Goto_Statement
kono
parents:
diff changeset
886
kono
parents:
diff changeset
887 when Tok_Goto =>
kono
parents:
diff changeset
888 Check_Bad_Layout;
kono
parents:
diff changeset
889 Append_To (Statement_List, P_Goto_Statement);
kono
parents:
diff changeset
890 Statement_Required := False;
kono
parents:
diff changeset
891
kono
parents:
diff changeset
892 -- If_Statement
kono
parents:
diff changeset
893
kono
parents:
diff changeset
894 when Tok_If =>
kono
parents:
diff changeset
895 Check_Bad_Layout;
kono
parents:
diff changeset
896 Append_To (Statement_List, P_If_Statement);
kono
parents:
diff changeset
897 Statement_Required := False;
kono
parents:
diff changeset
898
kono
parents:
diff changeset
899 -- Loop_Statement
kono
parents:
diff changeset
900
kono
parents:
diff changeset
901 when Tok_Loop =>
kono
parents:
diff changeset
902 Check_Bad_Layout;
kono
parents:
diff changeset
903 Append_To (Statement_List, P_Loop_Statement);
kono
parents:
diff changeset
904 Statement_Required := False;
kono
parents:
diff changeset
905
kono
parents:
diff changeset
906 -- Null_Statement
kono
parents:
diff changeset
907
kono
parents:
diff changeset
908 when Tok_Null =>
kono
parents:
diff changeset
909 Check_Bad_Layout;
kono
parents:
diff changeset
910 Append_To (Statement_List, P_Null_Statement);
kono
parents:
diff changeset
911 Statement_Required := False;
kono
parents:
diff changeset
912
kono
parents:
diff changeset
913 -- Raise_Statement
kono
parents:
diff changeset
914
kono
parents:
diff changeset
915 when Tok_Raise =>
kono
parents:
diff changeset
916 Check_Bad_Layout;
kono
parents:
diff changeset
917 Append_To (Statement_List, P_Raise_Statement);
kono
parents:
diff changeset
918 Statement_Required := False;
kono
parents:
diff changeset
919
kono
parents:
diff changeset
920 -- Requeue_Statement
kono
parents:
diff changeset
921
kono
parents:
diff changeset
922 when Tok_Requeue =>
kono
parents:
diff changeset
923 Check_Bad_Layout;
kono
parents:
diff changeset
924 Append_To (Statement_List, P_Requeue_Statement);
kono
parents:
diff changeset
925 Statement_Required := False;
kono
parents:
diff changeset
926
kono
parents:
diff changeset
927 -- Return_Statement
kono
parents:
diff changeset
928
kono
parents:
diff changeset
929 when Tok_Return =>
kono
parents:
diff changeset
930 Check_Bad_Layout;
kono
parents:
diff changeset
931 Append_To (Statement_List, P_Return_Statement);
kono
parents:
diff changeset
932 Statement_Required := False;
kono
parents:
diff changeset
933
kono
parents:
diff changeset
934 -- Select_Statement
kono
parents:
diff changeset
935
kono
parents:
diff changeset
936 when Tok_Select =>
kono
parents:
diff changeset
937 Check_Bad_Layout;
kono
parents:
diff changeset
938 Append_To (Statement_List, P_Select_Statement);
kono
parents:
diff changeset
939 Statement_Required := False;
kono
parents:
diff changeset
940
kono
parents:
diff changeset
941 -- While_Statement (Block_Statement with while and no loop)
kono
parents:
diff changeset
942
kono
parents:
diff changeset
943 when Tok_While =>
kono
parents:
diff changeset
944 Check_Bad_Layout;
kono
parents:
diff changeset
945 Append_To (Statement_List, P_While_Statement);
kono
parents:
diff changeset
946 Statement_Required := False;
kono
parents:
diff changeset
947
kono
parents:
diff changeset
948 -- Anything else is some kind of junk, signal an error message
kono
parents:
diff changeset
949 -- and then raise Error_Resync, to merge with the normal
kono
parents:
diff changeset
950 -- handling of a bad statement.
kono
parents:
diff changeset
951
kono
parents:
diff changeset
952 when others =>
kono
parents:
diff changeset
953 if Token in Token_Class_Declk then
kono
parents:
diff changeset
954 Junk_Declaration;
kono
parents:
diff changeset
955
kono
parents:
diff changeset
956 else
kono
parents:
diff changeset
957 Error_Msg_BC -- CODEFIX
kono
parents:
diff changeset
958 ("statement expected");
kono
parents:
diff changeset
959 raise Error_Resync;
kono
parents:
diff changeset
960 end if;
kono
parents:
diff changeset
961 end case;
kono
parents:
diff changeset
962
kono
parents:
diff changeset
963 -- On error resynchronization, skip past next semicolon, and, since
kono
parents:
diff changeset
964 -- we are still in the statement loop, look for next statement. We
kono
parents:
diff changeset
965 -- set Statement_Required False to avoid an unnecessary error message
kono
parents:
diff changeset
966 -- complaining that no statement was found (i.e. we consider the
kono
parents:
diff changeset
967 -- junk to satisfy the requirement for a statement being present).
kono
parents:
diff changeset
968
kono
parents:
diff changeset
969 exception
kono
parents:
diff changeset
970 when Error_Resync =>
kono
parents:
diff changeset
971 Resync_Past_Semicolon_Or_To_Loop_Or_Then;
kono
parents:
diff changeset
972 Statement_Required := False;
kono
parents:
diff changeset
973 end;
kono
parents:
diff changeset
974
kono
parents:
diff changeset
975 exit when SS_Flags.Unco;
kono
parents:
diff changeset
976 end loop;
kono
parents:
diff changeset
977
kono
parents:
diff changeset
978 return Statement_List;
kono
parents:
diff changeset
979 end P_Sequence_Of_Statements;
kono
parents:
diff changeset
980
kono
parents:
diff changeset
981 --------------------
kono
parents:
diff changeset
982 -- 5.1 Statement --
kono
parents:
diff changeset
983 --------------------
kono
parents:
diff changeset
984
kono
parents:
diff changeset
985 ---------------------------
kono
parents:
diff changeset
986 -- 5.1 Simple Statement --
kono
parents:
diff changeset
987 ---------------------------
kono
parents:
diff changeset
988
kono
parents:
diff changeset
989 -- Parsed by P_Sequence_Of_Statements (5.1)
kono
parents:
diff changeset
990
kono
parents:
diff changeset
991 -----------------------------
kono
parents:
diff changeset
992 -- 5.1 Compound Statement --
kono
parents:
diff changeset
993 -----------------------------
kono
parents:
diff changeset
994
kono
parents:
diff changeset
995 -- Parsed by P_Sequence_Of_Statements (5.1)
kono
parents:
diff changeset
996
kono
parents:
diff changeset
997 -------------------------
kono
parents:
diff changeset
998 -- 5.1 Null Statement --
kono
parents:
diff changeset
999 -------------------------
kono
parents:
diff changeset
1000
kono
parents:
diff changeset
1001 -- NULL_STATEMENT ::= null;
kono
parents:
diff changeset
1002
kono
parents:
diff changeset
1003 -- The caller has already checked that the current token is null
kono
parents:
diff changeset
1004
kono
parents:
diff changeset
1005 -- Error recovery: cannot raise Error_Resync
kono
parents:
diff changeset
1006
kono
parents:
diff changeset
1007 function P_Null_Statement return Node_Id is
kono
parents:
diff changeset
1008 Null_Stmt_Node : Node_Id;
kono
parents:
diff changeset
1009
kono
parents:
diff changeset
1010 begin
kono
parents:
diff changeset
1011 Null_Stmt_Node := New_Node (N_Null_Statement, Token_Ptr);
kono
parents:
diff changeset
1012 Scan; -- past NULL
kono
parents:
diff changeset
1013 TF_Semicolon;
kono
parents:
diff changeset
1014 return Null_Stmt_Node;
kono
parents:
diff changeset
1015 end P_Null_Statement;
kono
parents:
diff changeset
1016
kono
parents:
diff changeset
1017 ----------------
kono
parents:
diff changeset
1018 -- 5.1 Label --
kono
parents:
diff changeset
1019 ----------------
kono
parents:
diff changeset
1020
kono
parents:
diff changeset
1021 -- LABEL ::= <<label_STATEMENT_IDENTIFIER>>
kono
parents:
diff changeset
1022
kono
parents:
diff changeset
1023 -- STATEMENT_IDENTIFIER ::= DIRECT_NAME
kono
parents:
diff changeset
1024
kono
parents:
diff changeset
1025 -- The IDENTIFIER of a STATEMENT_IDENTIFIER shall be an identifier
kono
parents:
diff changeset
1026 -- (not an OPERATOR_SYMBOL)
kono
parents:
diff changeset
1027
kono
parents:
diff changeset
1028 -- The caller has already checked that the current token is <<
kono
parents:
diff changeset
1029
kono
parents:
diff changeset
1030 -- Error recovery: can raise Error_Resync
kono
parents:
diff changeset
1031
kono
parents:
diff changeset
1032 function P_Label return Node_Id is
kono
parents:
diff changeset
1033 Label_Node : Node_Id;
kono
parents:
diff changeset
1034
kono
parents:
diff changeset
1035 begin
kono
parents:
diff changeset
1036 Label_Node := New_Node (N_Label, Token_Ptr);
kono
parents:
diff changeset
1037 Scan; -- past <<
kono
parents:
diff changeset
1038 Set_Identifier (Label_Node, P_Identifier (C_Greater_Greater));
kono
parents:
diff changeset
1039 T_Greater_Greater;
kono
parents:
diff changeset
1040 Append_Elmt (Label_Node, Label_List);
kono
parents:
diff changeset
1041 return Label_Node;
kono
parents:
diff changeset
1042 end P_Label;
kono
parents:
diff changeset
1043
kono
parents:
diff changeset
1044 -------------------------------
kono
parents:
diff changeset
1045 -- 5.1 Statement Identifier --
kono
parents:
diff changeset
1046 -------------------------------
kono
parents:
diff changeset
1047
kono
parents:
diff changeset
1048 -- Statement label is parsed by P_Label (5.1)
kono
parents:
diff changeset
1049
kono
parents:
diff changeset
1050 -- Loop label is parsed by P_Loop_Statement (5.5), P_For_Statement (5.5)
kono
parents:
diff changeset
1051 -- or P_While_Statement (5.5)
kono
parents:
diff changeset
1052
kono
parents:
diff changeset
1053 -- Block label is parsed by P_Begin_Statement (5.6) or
kono
parents:
diff changeset
1054 -- P_Declare_Statement (5.6)
kono
parents:
diff changeset
1055
kono
parents:
diff changeset
1056 -------------------------------
kono
parents:
diff changeset
1057 -- 5.2 Assignment Statement --
kono
parents:
diff changeset
1058 -------------------------------
kono
parents:
diff changeset
1059
kono
parents:
diff changeset
1060 -- ASSIGNMENT_STATEMENT ::=
kono
parents:
diff changeset
1061 -- variable_NAME := EXPRESSION;
kono
parents:
diff changeset
1062
kono
parents:
diff changeset
1063 -- Error recovery: can raise Error_Resync
kono
parents:
diff changeset
1064
kono
parents:
diff changeset
1065 function P_Assignment_Statement (LHS : Node_Id) return Node_Id is
kono
parents:
diff changeset
1066 Assign_Node : Node_Id;
kono
parents:
diff changeset
1067
kono
parents:
diff changeset
1068 begin
kono
parents:
diff changeset
1069 Assign_Node := New_Node (N_Assignment_Statement, Prev_Token_Ptr);
kono
parents:
diff changeset
1070 Current_Assign_Node := Assign_Node;
kono
parents:
diff changeset
1071 Set_Name (Assign_Node, LHS);
kono
parents:
diff changeset
1072 Set_Expression (Assign_Node, P_Expression_No_Right_Paren);
kono
parents:
diff changeset
1073 TF_Semicolon;
kono
parents:
diff changeset
1074 Current_Assign_Node := Empty;
kono
parents:
diff changeset
1075 return Assign_Node;
kono
parents:
diff changeset
1076 end P_Assignment_Statement;
kono
parents:
diff changeset
1077
kono
parents:
diff changeset
1078 -----------------------
kono
parents:
diff changeset
1079 -- 5.3 If Statement --
kono
parents:
diff changeset
1080 -----------------------
kono
parents:
diff changeset
1081
kono
parents:
diff changeset
1082 -- IF_STATEMENT ::=
kono
parents:
diff changeset
1083 -- if CONDITION then
kono
parents:
diff changeset
1084 -- SEQUENCE_OF_STATEMENTS
kono
parents:
diff changeset
1085 -- {elsif CONDITION then
kono
parents:
diff changeset
1086 -- SEQUENCE_OF_STATEMENTS}
kono
parents:
diff changeset
1087 -- [else
kono
parents:
diff changeset
1088 -- SEQUENCE_OF_STATEMENTS]
kono
parents:
diff changeset
1089 -- end if;
kono
parents:
diff changeset
1090
kono
parents:
diff changeset
1091 -- The caller has checked that the initial token is IF (or in the error
kono
parents:
diff changeset
1092 -- case of a mysterious THEN, the initial token may simply be THEN, in
kono
parents:
diff changeset
1093 -- which case, no condition (or IF) was scanned).
kono
parents:
diff changeset
1094
kono
parents:
diff changeset
1095 -- Error recovery: can raise Error_Resync
kono
parents:
diff changeset
1096
kono
parents:
diff changeset
1097 function P_If_Statement return Node_Id is
kono
parents:
diff changeset
1098 If_Node : Node_Id;
kono
parents:
diff changeset
1099 Elsif_Node : Node_Id;
kono
parents:
diff changeset
1100 Loc : Source_Ptr;
kono
parents:
diff changeset
1101
kono
parents:
diff changeset
1102 procedure Add_Elsif_Part;
kono
parents:
diff changeset
1103 -- An internal procedure used to scan out a single ELSIF part. On entry
kono
parents:
diff changeset
1104 -- the ELSIF (or an ELSE which has been determined should be ELSIF) is
kono
parents:
diff changeset
1105 -- scanned out and is in Prev_Token.
kono
parents:
diff changeset
1106
kono
parents:
diff changeset
1107 procedure Check_If_Column;
kono
parents:
diff changeset
1108 -- An internal procedure used to check that THEN, ELSE, or ELSIF
kono
parents:
diff changeset
1109 -- appear in the right place if column checking is enabled (i.e. if
kono
parents:
diff changeset
1110 -- they are the first token on the line, then they must appear in
kono
parents:
diff changeset
1111 -- the same column as the opening IF).
kono
parents:
diff changeset
1112
kono
parents:
diff changeset
1113 procedure Check_Then_Column;
kono
parents:
diff changeset
1114 -- This procedure carries out the style checks for a THEN token
kono
parents:
diff changeset
1115 -- Note that the caller has set Loc to the Source_Ptr value for
kono
parents:
diff changeset
1116 -- the previous IF or ELSIF token.
kono
parents:
diff changeset
1117
kono
parents:
diff changeset
1118 function Else_Should_Be_Elsif return Boolean;
kono
parents:
diff changeset
1119 -- An internal routine used to do a special error recovery check when
kono
parents:
diff changeset
1120 -- an ELSE is encountered. It determines if the ELSE should be treated
kono
parents:
diff changeset
1121 -- as an ELSIF. A positive decision (TRUE returned, is made if the ELSE
kono
parents:
diff changeset
1122 -- is followed by a sequence of tokens, starting on the same line as
kono
parents:
diff changeset
1123 -- the ELSE, which are not expression terminators, followed by a THEN.
kono
parents:
diff changeset
1124 -- On entry, the ELSE has been scanned out.
kono
parents:
diff changeset
1125
kono
parents:
diff changeset
1126 procedure Add_Elsif_Part is
kono
parents:
diff changeset
1127 begin
kono
parents:
diff changeset
1128 if No (Elsif_Parts (If_Node)) then
kono
parents:
diff changeset
1129 Set_Elsif_Parts (If_Node, New_List);
kono
parents:
diff changeset
1130 end if;
kono
parents:
diff changeset
1131
kono
parents:
diff changeset
1132 Elsif_Node := New_Node (N_Elsif_Part, Prev_Token_Ptr);
kono
parents:
diff changeset
1133 Loc := Prev_Token_Ptr;
kono
parents:
diff changeset
1134 Set_Condition (Elsif_Node, P_Condition);
kono
parents:
diff changeset
1135 Check_Then_Column;
kono
parents:
diff changeset
1136 Then_Scan;
kono
parents:
diff changeset
1137 Set_Then_Statements
kono
parents:
diff changeset
1138 (Elsif_Node, P_Sequence_Of_Statements (SS_Eftm_Eltm_Sreq));
kono
parents:
diff changeset
1139 Append (Elsif_Node, Elsif_Parts (If_Node));
kono
parents:
diff changeset
1140 end Add_Elsif_Part;
kono
parents:
diff changeset
1141
kono
parents:
diff changeset
1142 procedure Check_If_Column is
kono
parents:
diff changeset
1143 begin
kono
parents:
diff changeset
1144 if RM_Column_Check and then Token_Is_At_Start_Of_Line
kono
parents:
diff changeset
1145 and then Start_Column /= Scope.Table (Scope.Last).Ecol
kono
parents:
diff changeset
1146 then
kono
parents:
diff changeset
1147 Error_Msg_Col := Scope.Table (Scope.Last).Ecol;
kono
parents:
diff changeset
1148 Error_Msg_SC ("(style) this token should be@");
kono
parents:
diff changeset
1149 end if;
kono
parents:
diff changeset
1150 end Check_If_Column;
kono
parents:
diff changeset
1151
kono
parents:
diff changeset
1152 procedure Check_Then_Column is
kono
parents:
diff changeset
1153 begin
kono
parents:
diff changeset
1154 if Token = Tok_Then then
kono
parents:
diff changeset
1155 Check_If_Column;
kono
parents:
diff changeset
1156
kono
parents:
diff changeset
1157 if Style_Check then
kono
parents:
diff changeset
1158 Style.Check_Then (Loc);
kono
parents:
diff changeset
1159 end if;
kono
parents:
diff changeset
1160 end if;
kono
parents:
diff changeset
1161 end Check_Then_Column;
kono
parents:
diff changeset
1162
kono
parents:
diff changeset
1163 function Else_Should_Be_Elsif return Boolean is
kono
parents:
diff changeset
1164 Scan_State : Saved_Scan_State;
kono
parents:
diff changeset
1165
kono
parents:
diff changeset
1166 begin
kono
parents:
diff changeset
1167 if Token_Is_At_Start_Of_Line then
kono
parents:
diff changeset
1168 return False;
kono
parents:
diff changeset
1169
kono
parents:
diff changeset
1170 else
kono
parents:
diff changeset
1171 Save_Scan_State (Scan_State);
kono
parents:
diff changeset
1172
kono
parents:
diff changeset
1173 loop
kono
parents:
diff changeset
1174 if Token in Token_Class_Eterm then
kono
parents:
diff changeset
1175 Restore_Scan_State (Scan_State);
kono
parents:
diff changeset
1176 return False;
kono
parents:
diff changeset
1177 else
kono
parents:
diff changeset
1178 Scan; -- past non-expression terminating token
kono
parents:
diff changeset
1179
kono
parents:
diff changeset
1180 if Token = Tok_Then then
kono
parents:
diff changeset
1181 Restore_Scan_State (Scan_State);
kono
parents:
diff changeset
1182 return True;
kono
parents:
diff changeset
1183 end if;
kono
parents:
diff changeset
1184 end if;
kono
parents:
diff changeset
1185 end loop;
kono
parents:
diff changeset
1186 end if;
kono
parents:
diff changeset
1187 end Else_Should_Be_Elsif;
kono
parents:
diff changeset
1188
kono
parents:
diff changeset
1189 -- Start of processing for P_If_Statement
kono
parents:
diff changeset
1190
kono
parents:
diff changeset
1191 begin
kono
parents:
diff changeset
1192 If_Node := New_Node (N_If_Statement, Token_Ptr);
kono
parents:
diff changeset
1193
kono
parents:
diff changeset
1194 Push_Scope_Stack;
kono
parents:
diff changeset
1195 Scope.Table (Scope.Last).Etyp := E_If;
kono
parents:
diff changeset
1196 Scope.Table (Scope.Last).Ecol := Start_Column;
kono
parents:
diff changeset
1197 Scope.Table (Scope.Last).Sloc := Token_Ptr;
kono
parents:
diff changeset
1198 Scope.Table (Scope.Last).Labl := Error;
kono
parents:
diff changeset
1199 Scope.Table (Scope.Last).Node := If_Node;
kono
parents:
diff changeset
1200
kono
parents:
diff changeset
1201 if Token = Tok_If then
kono
parents:
diff changeset
1202 Loc := Token_Ptr;
kono
parents:
diff changeset
1203 Scan; -- past IF
kono
parents:
diff changeset
1204 Set_Condition (If_Node, P_Condition);
kono
parents:
diff changeset
1205
kono
parents:
diff changeset
1206 -- Deal with misuse of IF expression => used instead
kono
parents:
diff changeset
1207 -- of WHEN expression =>
kono
parents:
diff changeset
1208
kono
parents:
diff changeset
1209 if Token = Tok_Arrow then
kono
parents:
diff changeset
1210 Error_Msg_SC -- CODEFIX
kono
parents:
diff changeset
1211 ("THEN expected");
kono
parents:
diff changeset
1212 Scan; -- past the arrow
kono
parents:
diff changeset
1213 Pop_Scope_Stack; -- remove unneeded entry
kono
parents:
diff changeset
1214 raise Error_Resync;
kono
parents:
diff changeset
1215 end if;
kono
parents:
diff changeset
1216
kono
parents:
diff changeset
1217 Check_Then_Column;
kono
parents:
diff changeset
1218
kono
parents:
diff changeset
1219 else
kono
parents:
diff changeset
1220 Error_Msg_SC ("no IF for this THEN");
kono
parents:
diff changeset
1221 Set_Condition (If_Node, Error);
kono
parents:
diff changeset
1222 end if;
kono
parents:
diff changeset
1223
kono
parents:
diff changeset
1224 Then_Scan;
kono
parents:
diff changeset
1225
kono
parents:
diff changeset
1226 Set_Then_Statements
kono
parents:
diff changeset
1227 (If_Node, P_Sequence_Of_Statements (SS_Eftm_Eltm_Sreq));
kono
parents:
diff changeset
1228
kono
parents:
diff changeset
1229 -- This loop scans out else and elsif parts
kono
parents:
diff changeset
1230
kono
parents:
diff changeset
1231 loop
kono
parents:
diff changeset
1232 if Token = Tok_Elsif then
kono
parents:
diff changeset
1233 Check_If_Column;
kono
parents:
diff changeset
1234
kono
parents:
diff changeset
1235 if Present (Else_Statements (If_Node)) then
kono
parents:
diff changeset
1236 Error_Msg_SP ("ELSIF cannot appear after ELSE");
kono
parents:
diff changeset
1237 end if;
kono
parents:
diff changeset
1238
kono
parents:
diff changeset
1239 Scan; -- past ELSIF
kono
parents:
diff changeset
1240 Add_Elsif_Part;
kono
parents:
diff changeset
1241
kono
parents:
diff changeset
1242 elsif Token = Tok_Else then
kono
parents:
diff changeset
1243 Check_If_Column;
kono
parents:
diff changeset
1244 Scan; -- past ELSE
kono
parents:
diff changeset
1245
kono
parents:
diff changeset
1246 if Else_Should_Be_Elsif then
kono
parents:
diff changeset
1247 Error_Msg_SP -- CODEFIX
kono
parents:
diff changeset
1248 ("ELSE should be ELSIF");
kono
parents:
diff changeset
1249 Add_Elsif_Part;
kono
parents:
diff changeset
1250
kono
parents:
diff changeset
1251 else
kono
parents:
diff changeset
1252 -- Here we have an else that really is an else
kono
parents:
diff changeset
1253
kono
parents:
diff changeset
1254 if Present (Else_Statements (If_Node)) then
kono
parents:
diff changeset
1255 Error_Msg_SP ("only one ELSE part allowed");
kono
parents:
diff changeset
1256 Append_List
kono
parents:
diff changeset
1257 (P_Sequence_Of_Statements (SS_Eftm_Eltm_Sreq),
kono
parents:
diff changeset
1258 Else_Statements (If_Node));
kono
parents:
diff changeset
1259 else
kono
parents:
diff changeset
1260 Set_Else_Statements
kono
parents:
diff changeset
1261 (If_Node, P_Sequence_Of_Statements (SS_Eftm_Eltm_Sreq));
kono
parents:
diff changeset
1262 end if;
kono
parents:
diff changeset
1263 end if;
kono
parents:
diff changeset
1264
kono
parents:
diff changeset
1265 -- If anything other than ELSE or ELSIF, exit the loop. The token
kono
parents:
diff changeset
1266 -- had better be END (and in fact it had better be END IF), but
kono
parents:
diff changeset
1267 -- we will let End_Statements take care of checking that.
kono
parents:
diff changeset
1268
kono
parents:
diff changeset
1269 else
kono
parents:
diff changeset
1270 exit;
kono
parents:
diff changeset
1271 end if;
kono
parents:
diff changeset
1272 end loop;
kono
parents:
diff changeset
1273
kono
parents:
diff changeset
1274 End_Statements;
kono
parents:
diff changeset
1275 return If_Node;
kono
parents:
diff changeset
1276
kono
parents:
diff changeset
1277 end P_If_Statement;
kono
parents:
diff changeset
1278
kono
parents:
diff changeset
1279 --------------------
kono
parents:
diff changeset
1280 -- 5.3 Condition --
kono
parents:
diff changeset
1281 --------------------
kono
parents:
diff changeset
1282
kono
parents:
diff changeset
1283 -- CONDITION ::= boolean_EXPRESSION
kono
parents:
diff changeset
1284
kono
parents:
diff changeset
1285 function P_Condition return Node_Id is
kono
parents:
diff changeset
1286 begin
kono
parents:
diff changeset
1287 return P_Condition (P_Expression_No_Right_Paren);
kono
parents:
diff changeset
1288 end P_Condition;
kono
parents:
diff changeset
1289
kono
parents:
diff changeset
1290 function P_Condition (Cond : Node_Id) return Node_Id is
kono
parents:
diff changeset
1291 begin
kono
parents:
diff changeset
1292 -- It is never possible for := to follow a condition, so if we get
kono
parents:
diff changeset
1293 -- a := we assume it is a mistyped equality. Note that we do not try
kono
parents:
diff changeset
1294 -- to reconstruct the tree correctly in this case, but we do at least
kono
parents:
diff changeset
1295 -- give an accurate error message.
kono
parents:
diff changeset
1296
kono
parents:
diff changeset
1297 if Token = Tok_Colon_Equal then
kono
parents:
diff changeset
1298 while Token = Tok_Colon_Equal loop
kono
parents:
diff changeset
1299 Error_Msg_SC -- CODEFIX
kono
parents:
diff changeset
1300 (""":="" should be ""=""");
kono
parents:
diff changeset
1301 Scan; -- past junk :=
kono
parents:
diff changeset
1302 Discard_Junk_Node (P_Expression_No_Right_Paren);
kono
parents:
diff changeset
1303 end loop;
kono
parents:
diff changeset
1304
kono
parents:
diff changeset
1305 return Cond;
kono
parents:
diff changeset
1306
kono
parents:
diff changeset
1307 -- Otherwise check for redundant parentheses
kono
parents:
diff changeset
1308
kono
parents:
diff changeset
1309 -- If the condition is a conditional or a quantified expression, it is
kono
parents:
diff changeset
1310 -- parenthesized in the context of a condition, because of a separate
kono
parents:
diff changeset
1311 -- syntax rule.
kono
parents:
diff changeset
1312
kono
parents:
diff changeset
1313 else
kono
parents:
diff changeset
1314 if Style_Check and then Paren_Count (Cond) > 0 then
kono
parents:
diff changeset
1315 if not Nkind_In (Cond, N_If_Expression,
kono
parents:
diff changeset
1316 N_Case_Expression,
kono
parents:
diff changeset
1317 N_Quantified_Expression)
kono
parents:
diff changeset
1318 or else Paren_Count (Cond) > 1
kono
parents:
diff changeset
1319 then
kono
parents:
diff changeset
1320 Style.Check_Xtra_Parens (First_Sloc (Cond));
kono
parents:
diff changeset
1321 end if;
kono
parents:
diff changeset
1322 end if;
kono
parents:
diff changeset
1323
kono
parents:
diff changeset
1324 -- And return the result
kono
parents:
diff changeset
1325
kono
parents:
diff changeset
1326 return Cond;
kono
parents:
diff changeset
1327 end if;
kono
parents:
diff changeset
1328 end P_Condition;
kono
parents:
diff changeset
1329
kono
parents:
diff changeset
1330 -------------------------
kono
parents:
diff changeset
1331 -- 5.4 Case Statement --
kono
parents:
diff changeset
1332 -------------------------
kono
parents:
diff changeset
1333
kono
parents:
diff changeset
1334 -- CASE_STATEMENT ::=
kono
parents:
diff changeset
1335 -- case EXPRESSION is
kono
parents:
diff changeset
1336 -- CASE_STATEMENT_ALTERNATIVE
kono
parents:
diff changeset
1337 -- {CASE_STATEMENT_ALTERNATIVE}
kono
parents:
diff changeset
1338 -- end case;
kono
parents:
diff changeset
1339
kono
parents:
diff changeset
1340 -- The caller has checked that the first token is CASE
kono
parents:
diff changeset
1341
kono
parents:
diff changeset
1342 -- Can raise Error_Resync
kono
parents:
diff changeset
1343
kono
parents:
diff changeset
1344 function P_Case_Statement return Node_Id is
kono
parents:
diff changeset
1345 Case_Node : Node_Id;
kono
parents:
diff changeset
1346 Alternatives_List : List_Id;
kono
parents:
diff changeset
1347 First_When_Loc : Source_Ptr;
kono
parents:
diff changeset
1348
kono
parents:
diff changeset
1349 begin
kono
parents:
diff changeset
1350 Case_Node := New_Node (N_Case_Statement, Token_Ptr);
kono
parents:
diff changeset
1351
kono
parents:
diff changeset
1352 Push_Scope_Stack;
kono
parents:
diff changeset
1353 Scope.Table (Scope.Last).Etyp := E_Case;
kono
parents:
diff changeset
1354 Scope.Table (Scope.Last).Ecol := Start_Column;
kono
parents:
diff changeset
1355 Scope.Table (Scope.Last).Sloc := Token_Ptr;
kono
parents:
diff changeset
1356 Scope.Table (Scope.Last).Labl := Error;
kono
parents:
diff changeset
1357 Scope.Table (Scope.Last).Node := Case_Node;
kono
parents:
diff changeset
1358
kono
parents:
diff changeset
1359 Scan; -- past CASE
kono
parents:
diff changeset
1360 Set_Expression (Case_Node, P_Expression_No_Right_Paren);
kono
parents:
diff changeset
1361 TF_Is;
kono
parents:
diff changeset
1362
kono
parents:
diff changeset
1363 -- Prepare to parse case statement alternatives
kono
parents:
diff changeset
1364
kono
parents:
diff changeset
1365 Alternatives_List := New_List;
kono
parents:
diff changeset
1366 P_Pragmas_Opt (Alternatives_List);
kono
parents:
diff changeset
1367 First_When_Loc := Token_Ptr;
kono
parents:
diff changeset
1368
kono
parents:
diff changeset
1369 -- Loop through case statement alternatives
kono
parents:
diff changeset
1370
kono
parents:
diff changeset
1371 loop
kono
parents:
diff changeset
1372 -- If we have a WHEN or OTHERS, then that's fine keep going. Note
kono
parents:
diff changeset
1373 -- that it is a semantic check to ensure the proper use of OTHERS
kono
parents:
diff changeset
1374
kono
parents:
diff changeset
1375 if Token = Tok_When or else Token = Tok_Others then
kono
parents:
diff changeset
1376 Append (P_Case_Statement_Alternative, Alternatives_List);
kono
parents:
diff changeset
1377
kono
parents:
diff changeset
1378 -- If we have an END, then probably we are at the end of the case
kono
parents:
diff changeset
1379 -- but we only exit if Check_End thinks the END was reasonable.
kono
parents:
diff changeset
1380
kono
parents:
diff changeset
1381 elsif Token = Tok_End then
kono
parents:
diff changeset
1382 exit when Check_End;
kono
parents:
diff changeset
1383
kono
parents:
diff changeset
1384 -- Here if token is other than WHEN, OTHERS or END. We definitely
kono
parents:
diff changeset
1385 -- have an error, but the question is whether or not to get out of
kono
parents:
diff changeset
1386 -- the case statement. We don't want to get out early, or we will
kono
parents:
diff changeset
1387 -- get a slew of junk error messages for subsequent when tokens.
kono
parents:
diff changeset
1388
kono
parents:
diff changeset
1389 -- If the token is not at the start of the line, or if it is indented
kono
parents:
diff changeset
1390 -- with respect to the current case statement, then the best guess is
kono
parents:
diff changeset
1391 -- that we are still supposed to be inside the case statement. We
kono
parents:
diff changeset
1392 -- complain about the missing WHEN, and discard the junk statements.
kono
parents:
diff changeset
1393
kono
parents:
diff changeset
1394 elsif not Token_Is_At_Start_Of_Line
kono
parents:
diff changeset
1395 or else Start_Column > Scope.Table (Scope.Last).Ecol
kono
parents:
diff changeset
1396 then
kono
parents:
diff changeset
1397 Error_Msg_BC ("WHEN (case statement alternative) expected");
kono
parents:
diff changeset
1398
kono
parents:
diff changeset
1399 -- Here is a possibility for infinite looping if we don't make
kono
parents:
diff changeset
1400 -- progress. So try to process statements, otherwise exit
kono
parents:
diff changeset
1401
kono
parents:
diff changeset
1402 declare
kono
parents:
diff changeset
1403 Error_Ptr : constant Source_Ptr := Scan_Ptr;
kono
parents:
diff changeset
1404 begin
kono
parents:
diff changeset
1405 Discard_Junk_List (P_Sequence_Of_Statements (SS_Whtm));
kono
parents:
diff changeset
1406 exit when Scan_Ptr = Error_Ptr and then Check_End;
kono
parents:
diff changeset
1407 end;
kono
parents:
diff changeset
1408
kono
parents:
diff changeset
1409 -- Here we have a junk token at the start of the line and it is
kono
parents:
diff changeset
1410 -- not indented. If Check_End thinks there is a missing END, then
kono
parents:
diff changeset
1411 -- we will get out of the case, otherwise we keep going.
kono
parents:
diff changeset
1412
kono
parents:
diff changeset
1413 else
kono
parents:
diff changeset
1414 exit when Check_End;
kono
parents:
diff changeset
1415 end if;
kono
parents:
diff changeset
1416 end loop;
kono
parents:
diff changeset
1417
kono
parents:
diff changeset
1418 -- Make sure we have at least one alternative
kono
parents:
diff changeset
1419
kono
parents:
diff changeset
1420 if No (First_Non_Pragma (Alternatives_List)) then
kono
parents:
diff changeset
1421 Error_Msg
kono
parents:
diff changeset
1422 ("WHEN expected, must have at least one alternative in case",
kono
parents:
diff changeset
1423 First_When_Loc);
kono
parents:
diff changeset
1424 return Error;
kono
parents:
diff changeset
1425
kono
parents:
diff changeset
1426 else
kono
parents:
diff changeset
1427 Set_Alternatives (Case_Node, Alternatives_List);
kono
parents:
diff changeset
1428 return Case_Node;
kono
parents:
diff changeset
1429 end if;
kono
parents:
diff changeset
1430 end P_Case_Statement;
kono
parents:
diff changeset
1431
kono
parents:
diff changeset
1432 -------------------------------------
kono
parents:
diff changeset
1433 -- 5.4 Case Statement Alternative --
kono
parents:
diff changeset
1434 -------------------------------------
kono
parents:
diff changeset
1435
kono
parents:
diff changeset
1436 -- CASE_STATEMENT_ALTERNATIVE ::=
kono
parents:
diff changeset
1437 -- when DISCRETE_CHOICE_LIST =>
kono
parents:
diff changeset
1438 -- SEQUENCE_OF_STATEMENTS
kono
parents:
diff changeset
1439
kono
parents:
diff changeset
1440 -- The caller has checked that the initial token is WHEN or OTHERS
kono
parents:
diff changeset
1441 -- Error recovery: can raise Error_Resync
kono
parents:
diff changeset
1442
kono
parents:
diff changeset
1443 function P_Case_Statement_Alternative return Node_Id is
kono
parents:
diff changeset
1444 Case_Alt_Node : Node_Id;
kono
parents:
diff changeset
1445
kono
parents:
diff changeset
1446 begin
kono
parents:
diff changeset
1447 if Style_Check then
kono
parents:
diff changeset
1448 Style.Check_Indentation;
kono
parents:
diff changeset
1449 end if;
kono
parents:
diff changeset
1450
kono
parents:
diff changeset
1451 Case_Alt_Node := New_Node (N_Case_Statement_Alternative, Token_Ptr);
kono
parents:
diff changeset
1452 T_When; -- past WHEN (or give error in OTHERS case)
kono
parents:
diff changeset
1453 Set_Discrete_Choices (Case_Alt_Node, P_Discrete_Choice_List);
kono
parents:
diff changeset
1454 TF_Arrow;
kono
parents:
diff changeset
1455 Set_Statements (Case_Alt_Node, P_Sequence_Of_Statements (SS_Sreq_Whtm));
kono
parents:
diff changeset
1456 return Case_Alt_Node;
kono
parents:
diff changeset
1457 end P_Case_Statement_Alternative;
kono
parents:
diff changeset
1458
kono
parents:
diff changeset
1459 -------------------------
kono
parents:
diff changeset
1460 -- 5.5 Loop Statement --
kono
parents:
diff changeset
1461 -------------------------
kono
parents:
diff changeset
1462
kono
parents:
diff changeset
1463 -- LOOP_STATEMENT ::=
kono
parents:
diff changeset
1464 -- [LOOP_STATEMENT_IDENTIFIER:]
kono
parents:
diff changeset
1465 -- [ITERATION_SCHEME] loop
kono
parents:
diff changeset
1466 -- SEQUENCE_OF_STATEMENTS
kono
parents:
diff changeset
1467 -- end loop [loop_IDENTIFIER];
kono
parents:
diff changeset
1468
kono
parents:
diff changeset
1469 -- ITERATION_SCHEME ::=
kono
parents:
diff changeset
1470 -- while CONDITION
kono
parents:
diff changeset
1471 -- | for LOOP_PARAMETER_SPECIFICATION
kono
parents:
diff changeset
1472
kono
parents:
diff changeset
1473 -- The parsing of loop statements is handled by one of three functions
kono
parents:
diff changeset
1474 -- P_Loop_Statement, P_For_Statement or P_While_Statement depending
kono
parents:
diff changeset
1475 -- on the initial keyword in the construct (excluding the identifier)
kono
parents:
diff changeset
1476
kono
parents:
diff changeset
1477 -- P_Loop_Statement
kono
parents:
diff changeset
1478
kono
parents:
diff changeset
1479 -- This function parses the case where no iteration scheme is present
kono
parents:
diff changeset
1480
kono
parents:
diff changeset
1481 -- The caller has checked that the initial token is LOOP. The parameter
kono
parents:
diff changeset
1482 -- is the node identifiers for the loop label if any (or is set to Empty
kono
parents:
diff changeset
1483 -- if there is no loop label).
kono
parents:
diff changeset
1484
kono
parents:
diff changeset
1485 -- Error recovery : cannot raise Error_Resync
kono
parents:
diff changeset
1486
kono
parents:
diff changeset
1487 function P_Loop_Statement (Loop_Name : Node_Id := Empty) return Node_Id is
kono
parents:
diff changeset
1488 Loop_Node : Node_Id;
kono
parents:
diff changeset
1489 Created_Name : Node_Id;
kono
parents:
diff changeset
1490
kono
parents:
diff changeset
1491 begin
kono
parents:
diff changeset
1492 Push_Scope_Stack;
kono
parents:
diff changeset
1493 Scope.Table (Scope.Last).Labl := Loop_Name;
kono
parents:
diff changeset
1494 Scope.Table (Scope.Last).Ecol := Start_Column;
kono
parents:
diff changeset
1495 Scope.Table (Scope.Last).Sloc := Token_Ptr;
kono
parents:
diff changeset
1496 Scope.Table (Scope.Last).Etyp := E_Loop;
kono
parents:
diff changeset
1497
kono
parents:
diff changeset
1498 Loop_Node := New_Node (N_Loop_Statement, Token_Ptr);
kono
parents:
diff changeset
1499 TF_Loop;
kono
parents:
diff changeset
1500
kono
parents:
diff changeset
1501 if No (Loop_Name) then
kono
parents:
diff changeset
1502 Created_Name :=
kono
parents:
diff changeset
1503 Make_Identifier (Sloc (Loop_Node), Set_Loop_Block_Name ('L'));
kono
parents:
diff changeset
1504 Set_Comes_From_Source (Created_Name, False);
kono
parents:
diff changeset
1505 Set_Has_Created_Identifier (Loop_Node, True);
kono
parents:
diff changeset
1506 Set_Identifier (Loop_Node, Created_Name);
kono
parents:
diff changeset
1507 Scope.Table (Scope.Last).Labl := Created_Name;
kono
parents:
diff changeset
1508 else
kono
parents:
diff changeset
1509 Set_Identifier (Loop_Node, Loop_Name);
kono
parents:
diff changeset
1510 end if;
kono
parents:
diff changeset
1511
kono
parents:
diff changeset
1512 Append_Elmt (Loop_Node, Label_List);
kono
parents:
diff changeset
1513 Set_Statements (Loop_Node, P_Sequence_Of_Statements (SS_Sreq));
kono
parents:
diff changeset
1514 End_Statements (Loop_Node);
kono
parents:
diff changeset
1515 return Loop_Node;
kono
parents:
diff changeset
1516 end P_Loop_Statement;
kono
parents:
diff changeset
1517
kono
parents:
diff changeset
1518 -- P_For_Statement
kono
parents:
diff changeset
1519
kono
parents:
diff changeset
1520 -- This function parses a loop statement with a FOR iteration scheme
kono
parents:
diff changeset
1521
kono
parents:
diff changeset
1522 -- The caller has checked that the initial token is FOR. The parameter
kono
parents:
diff changeset
1523 -- is the node identifier for the block label if any (or is set to Empty
kono
parents:
diff changeset
1524 -- if there is no block label).
kono
parents:
diff changeset
1525
kono
parents:
diff changeset
1526 -- Note: the caller fills in the Identifier field if a label was present
kono
parents:
diff changeset
1527
kono
parents:
diff changeset
1528 -- Error recovery: can raise Error_Resync
kono
parents:
diff changeset
1529
kono
parents:
diff changeset
1530 function P_For_Statement (Loop_Name : Node_Id := Empty) return Node_Id is
kono
parents:
diff changeset
1531 Loop_Node : Node_Id;
kono
parents:
diff changeset
1532 Iter_Scheme_Node : Node_Id;
kono
parents:
diff changeset
1533 Loop_For_Flag : Boolean;
kono
parents:
diff changeset
1534 Created_Name : Node_Id;
kono
parents:
diff changeset
1535 Spec : Node_Id;
kono
parents:
diff changeset
1536
kono
parents:
diff changeset
1537 begin
kono
parents:
diff changeset
1538 Push_Scope_Stack;
kono
parents:
diff changeset
1539 Scope.Table (Scope.Last).Labl := Loop_Name;
kono
parents:
diff changeset
1540 Scope.Table (Scope.Last).Ecol := Start_Column;
kono
parents:
diff changeset
1541 Scope.Table (Scope.Last).Sloc := Token_Ptr;
kono
parents:
diff changeset
1542 Scope.Table (Scope.Last).Etyp := E_Loop;
kono
parents:
diff changeset
1543
kono
parents:
diff changeset
1544 Loop_For_Flag := (Prev_Token = Tok_Loop);
kono
parents:
diff changeset
1545 Scan; -- past FOR
kono
parents:
diff changeset
1546 Iter_Scheme_Node := New_Node (N_Iteration_Scheme, Token_Ptr);
kono
parents:
diff changeset
1547 Spec := P_Loop_Parameter_Specification;
kono
parents:
diff changeset
1548
kono
parents:
diff changeset
1549 if Nkind (Spec) = N_Loop_Parameter_Specification then
kono
parents:
diff changeset
1550 Set_Loop_Parameter_Specification (Iter_Scheme_Node, Spec);
kono
parents:
diff changeset
1551 else
kono
parents:
diff changeset
1552 Set_Iterator_Specification (Iter_Scheme_Node, Spec);
kono
parents:
diff changeset
1553 end if;
kono
parents:
diff changeset
1554
kono
parents:
diff changeset
1555 -- The following is a special test so that a miswritten for loop such
kono
parents:
diff changeset
1556 -- as "loop for I in 1..10;" is handled nicely, without making an extra
kono
parents:
diff changeset
1557 -- entry in the scope stack. We don't bother to actually fix up the
kono
parents:
diff changeset
1558 -- tree in this case since it's not worth the effort. Instead we just
kono
parents:
diff changeset
1559 -- eat up the loop junk, leaving the entry for what now looks like an
kono
parents:
diff changeset
1560 -- unmodified loop intact.
kono
parents:
diff changeset
1561
kono
parents:
diff changeset
1562 if Loop_For_Flag and then Token = Tok_Semicolon then
kono
parents:
diff changeset
1563 Error_Msg_SC ("LOOP belongs here, not before FOR");
kono
parents:
diff changeset
1564 Pop_Scope_Stack;
kono
parents:
diff changeset
1565 return Error;
kono
parents:
diff changeset
1566
kono
parents:
diff changeset
1567 -- Normal case
kono
parents:
diff changeset
1568
kono
parents:
diff changeset
1569 else
kono
parents:
diff changeset
1570 Loop_Node := New_Node (N_Loop_Statement, Token_Ptr);
kono
parents:
diff changeset
1571
kono
parents:
diff changeset
1572 if No (Loop_Name) then
kono
parents:
diff changeset
1573 Created_Name :=
kono
parents:
diff changeset
1574 Make_Identifier (Sloc (Loop_Node), Set_Loop_Block_Name ('L'));
kono
parents:
diff changeset
1575 Set_Comes_From_Source (Created_Name, False);
kono
parents:
diff changeset
1576 Set_Has_Created_Identifier (Loop_Node, True);
kono
parents:
diff changeset
1577 Set_Identifier (Loop_Node, Created_Name);
kono
parents:
diff changeset
1578 Scope.Table (Scope.Last).Labl := Created_Name;
kono
parents:
diff changeset
1579 else
kono
parents:
diff changeset
1580 Set_Identifier (Loop_Node, Loop_Name);
kono
parents:
diff changeset
1581 end if;
kono
parents:
diff changeset
1582
kono
parents:
diff changeset
1583 TF_Loop;
kono
parents:
diff changeset
1584 Set_Statements (Loop_Node, P_Sequence_Of_Statements (SS_Sreq));
kono
parents:
diff changeset
1585 End_Statements (Loop_Node);
kono
parents:
diff changeset
1586 Set_Iteration_Scheme (Loop_Node, Iter_Scheme_Node);
kono
parents:
diff changeset
1587 Append_Elmt (Loop_Node, Label_List);
kono
parents:
diff changeset
1588 return Loop_Node;
kono
parents:
diff changeset
1589 end if;
kono
parents:
diff changeset
1590 end P_For_Statement;
kono
parents:
diff changeset
1591
kono
parents:
diff changeset
1592 -- P_While_Statement
kono
parents:
diff changeset
1593
kono
parents:
diff changeset
1594 -- This procedure scans a loop statement with a WHILE iteration scheme
kono
parents:
diff changeset
1595
kono
parents:
diff changeset
1596 -- The caller has checked that the initial token is WHILE. The parameter
kono
parents:
diff changeset
1597 -- is the node identifier for the block label if any (or is set to Empty
kono
parents:
diff changeset
1598 -- if there is no block label).
kono
parents:
diff changeset
1599
kono
parents:
diff changeset
1600 -- Error recovery: cannot raise Error_Resync
kono
parents:
diff changeset
1601
kono
parents:
diff changeset
1602 function P_While_Statement (Loop_Name : Node_Id := Empty) return Node_Id is
kono
parents:
diff changeset
1603 Loop_Node : Node_Id;
kono
parents:
diff changeset
1604 Iter_Scheme_Node : Node_Id;
kono
parents:
diff changeset
1605 Loop_While_Flag : Boolean;
kono
parents:
diff changeset
1606 Created_Name : Node_Id;
kono
parents:
diff changeset
1607
kono
parents:
diff changeset
1608 begin
kono
parents:
diff changeset
1609 Push_Scope_Stack;
kono
parents:
diff changeset
1610 Scope.Table (Scope.Last).Labl := Loop_Name;
kono
parents:
diff changeset
1611 Scope.Table (Scope.Last).Ecol := Start_Column;
kono
parents:
diff changeset
1612 Scope.Table (Scope.Last).Sloc := Token_Ptr;
kono
parents:
diff changeset
1613 Scope.Table (Scope.Last).Etyp := E_Loop;
kono
parents:
diff changeset
1614
kono
parents:
diff changeset
1615 Loop_While_Flag := (Prev_Token = Tok_Loop);
kono
parents:
diff changeset
1616 Iter_Scheme_Node := New_Node (N_Iteration_Scheme, Token_Ptr);
kono
parents:
diff changeset
1617 Scan; -- past WHILE
kono
parents:
diff changeset
1618 Set_Condition (Iter_Scheme_Node, P_Condition);
kono
parents:
diff changeset
1619
kono
parents:
diff changeset
1620 -- The following is a special test so that a miswritten for loop such
kono
parents:
diff changeset
1621 -- as "loop while I > 10;" is handled nicely, without making an extra
kono
parents:
diff changeset
1622 -- entry in the scope stack. We don't bother to actually fix up the
kono
parents:
diff changeset
1623 -- tree in this case since it's not worth the effort. Instead we just
kono
parents:
diff changeset
1624 -- eat up the loop junk, leaving the entry for what now looks like an
kono
parents:
diff changeset
1625 -- unmodified loop intact.
kono
parents:
diff changeset
1626
kono
parents:
diff changeset
1627 if Loop_While_Flag and then Token = Tok_Semicolon then
kono
parents:
diff changeset
1628 Error_Msg_SC ("LOOP belongs here, not before WHILE");
kono
parents:
diff changeset
1629 Pop_Scope_Stack;
kono
parents:
diff changeset
1630 return Error;
kono
parents:
diff changeset
1631
kono
parents:
diff changeset
1632 -- Normal case
kono
parents:
diff changeset
1633
kono
parents:
diff changeset
1634 else
kono
parents:
diff changeset
1635 Loop_Node := New_Node (N_Loop_Statement, Token_Ptr);
kono
parents:
diff changeset
1636 TF_Loop;
kono
parents:
diff changeset
1637
kono
parents:
diff changeset
1638 if No (Loop_Name) then
kono
parents:
diff changeset
1639 Created_Name :=
kono
parents:
diff changeset
1640 Make_Identifier (Sloc (Loop_Node), Set_Loop_Block_Name ('L'));
kono
parents:
diff changeset
1641 Set_Comes_From_Source (Created_Name, False);
kono
parents:
diff changeset
1642 Set_Has_Created_Identifier (Loop_Node, True);
kono
parents:
diff changeset
1643 Set_Identifier (Loop_Node, Created_Name);
kono
parents:
diff changeset
1644 Scope.Table (Scope.Last).Labl := Created_Name;
kono
parents:
diff changeset
1645 else
kono
parents:
diff changeset
1646 Set_Identifier (Loop_Node, Loop_Name);
kono
parents:
diff changeset
1647 end if;
kono
parents:
diff changeset
1648
kono
parents:
diff changeset
1649 Set_Statements (Loop_Node, P_Sequence_Of_Statements (SS_Sreq));
kono
parents:
diff changeset
1650 End_Statements (Loop_Node);
kono
parents:
diff changeset
1651 Set_Iteration_Scheme (Loop_Node, Iter_Scheme_Node);
kono
parents:
diff changeset
1652 Append_Elmt (Loop_Node, Label_List);
kono
parents:
diff changeset
1653 return Loop_Node;
kono
parents:
diff changeset
1654 end if;
kono
parents:
diff changeset
1655 end P_While_Statement;
kono
parents:
diff changeset
1656
kono
parents:
diff changeset
1657 ---------------------------------------
kono
parents:
diff changeset
1658 -- 5.5 Loop Parameter Specification --
kono
parents:
diff changeset
1659 ---------------------------------------
kono
parents:
diff changeset
1660
kono
parents:
diff changeset
1661 -- LOOP_PARAMETER_SPECIFICATION ::=
kono
parents:
diff changeset
1662 -- DEFINING_IDENTIFIER in [reverse] DISCRETE_SUBTYPE_DEFINITION
kono
parents:
diff changeset
1663
kono
parents:
diff changeset
1664 -- Error recovery: cannot raise Error_Resync
kono
parents:
diff changeset
1665
kono
parents:
diff changeset
1666 function P_Loop_Parameter_Specification return Node_Id is
kono
parents:
diff changeset
1667 Loop_Param_Specification_Node : Node_Id;
kono
parents:
diff changeset
1668
kono
parents:
diff changeset
1669 ID_Node : Node_Id;
kono
parents:
diff changeset
1670 Scan_State : Saved_Scan_State;
kono
parents:
diff changeset
1671
kono
parents:
diff changeset
1672 begin
kono
parents:
diff changeset
1673
kono
parents:
diff changeset
1674 Save_Scan_State (Scan_State);
kono
parents:
diff changeset
1675 ID_Node := P_Defining_Identifier (C_In);
kono
parents:
diff changeset
1676
kono
parents:
diff changeset
1677 -- If the next token is OF, it indicates an Ada 2012 iterator. If the
kono
parents:
diff changeset
1678 -- next token is a colon, this is also an Ada 2012 iterator, including
kono
parents:
diff changeset
1679 -- a subtype indication for the loop parameter. Otherwise we parse the
kono
parents:
diff changeset
1680 -- construct as a loop parameter specification. Note that the form
kono
parents:
diff changeset
1681 -- "for A in B" is ambiguous, and must be resolved semantically: if B
kono
parents:
diff changeset
1682 -- is a discrete subtype this is a loop specification, but if it is an
kono
parents:
diff changeset
1683 -- expression it is an iterator specification. Ambiguity is resolved
kono
parents:
diff changeset
1684 -- during analysis of the loop parameter specification.
kono
parents:
diff changeset
1685
kono
parents:
diff changeset
1686 if Token = Tok_Of or else Token = Tok_Colon then
kono
parents:
diff changeset
1687 Error_Msg_Ada_2012_Feature ("iterator", Token_Ptr);
kono
parents:
diff changeset
1688 return P_Iterator_Specification (ID_Node);
kono
parents:
diff changeset
1689 end if;
kono
parents:
diff changeset
1690
kono
parents:
diff changeset
1691 -- The span of the Loop_Parameter_Specification starts at the
kono
parents:
diff changeset
1692 -- defining identifier.
kono
parents:
diff changeset
1693
kono
parents:
diff changeset
1694 Loop_Param_Specification_Node :=
kono
parents:
diff changeset
1695 New_Node (N_Loop_Parameter_Specification, Sloc (ID_Node));
kono
parents:
diff changeset
1696 Set_Defining_Identifier (Loop_Param_Specification_Node, ID_Node);
kono
parents:
diff changeset
1697
kono
parents:
diff changeset
1698 if Token = Tok_Left_Paren then
kono
parents:
diff changeset
1699 Error_Msg_SC ("subscripted loop parameter not allowed");
kono
parents:
diff changeset
1700 Restore_Scan_State (Scan_State);
kono
parents:
diff changeset
1701 Discard_Junk_Node (P_Name);
kono
parents:
diff changeset
1702
kono
parents:
diff changeset
1703 elsif Token = Tok_Dot then
kono
parents:
diff changeset
1704 Error_Msg_SC ("selected loop parameter not allowed");
kono
parents:
diff changeset
1705 Restore_Scan_State (Scan_State);
kono
parents:
diff changeset
1706 Discard_Junk_Node (P_Name);
kono
parents:
diff changeset
1707 end if;
kono
parents:
diff changeset
1708
kono
parents:
diff changeset
1709 T_In;
kono
parents:
diff changeset
1710
kono
parents:
diff changeset
1711 if Token = Tok_Reverse then
kono
parents:
diff changeset
1712 Scan; -- past REVERSE
kono
parents:
diff changeset
1713 Set_Reverse_Present (Loop_Param_Specification_Node, True);
kono
parents:
diff changeset
1714 end if;
kono
parents:
diff changeset
1715
kono
parents:
diff changeset
1716 Set_Discrete_Subtype_Definition
kono
parents:
diff changeset
1717 (Loop_Param_Specification_Node, P_Discrete_Subtype_Definition);
kono
parents:
diff changeset
1718 return Loop_Param_Specification_Node;
kono
parents:
diff changeset
1719
kono
parents:
diff changeset
1720 exception
kono
parents:
diff changeset
1721 when Error_Resync =>
kono
parents:
diff changeset
1722 return Error;
kono
parents:
diff changeset
1723 end P_Loop_Parameter_Specification;
kono
parents:
diff changeset
1724
kono
parents:
diff changeset
1725 ----------------------------------
kono
parents:
diff changeset
1726 -- 5.5.1 Iterator_Specification --
kono
parents:
diff changeset
1727 ----------------------------------
kono
parents:
diff changeset
1728
kono
parents:
diff changeset
1729 function P_Iterator_Specification (Def_Id : Node_Id) return Node_Id is
kono
parents:
diff changeset
1730 Node1 : Node_Id;
kono
parents:
diff changeset
1731
kono
parents:
diff changeset
1732 begin
kono
parents:
diff changeset
1733 Node1 := New_Node (N_Iterator_Specification, Sloc (Def_Id));
kono
parents:
diff changeset
1734 Set_Defining_Identifier (Node1, Def_Id);
kono
parents:
diff changeset
1735
kono
parents:
diff changeset
1736 if Token = Tok_Colon then
kono
parents:
diff changeset
1737 Scan; -- past :
kono
parents:
diff changeset
1738 Set_Subtype_Indication (Node1, P_Subtype_Indication);
kono
parents:
diff changeset
1739 end if;
kono
parents:
diff changeset
1740
kono
parents:
diff changeset
1741 if Token = Tok_Of then
kono
parents:
diff changeset
1742 Set_Of_Present (Node1);
kono
parents:
diff changeset
1743 Scan; -- past OF
kono
parents:
diff changeset
1744
kono
parents:
diff changeset
1745 elsif Token = Tok_In then
kono
parents:
diff changeset
1746 Scan; -- past IN
kono
parents:
diff changeset
1747
kono
parents:
diff changeset
1748 elsif Prev_Token = Tok_In
kono
parents:
diff changeset
1749 and then Present (Subtype_Indication (Node1))
kono
parents:
diff changeset
1750 then
kono
parents:
diff changeset
1751 -- Simplest recovery is to transform it into an element iterator.
kono
parents:
diff changeset
1752 -- Error message on 'in" has already been emitted when parsing the
kono
parents:
diff changeset
1753 -- optional constraint.
kono
parents:
diff changeset
1754
kono
parents:
diff changeset
1755 Set_Of_Present (Node1);
kono
parents:
diff changeset
1756 Error_Msg_N
kono
parents:
diff changeset
1757 ("subtype indication is only legal on an element iterator",
kono
parents:
diff changeset
1758 Subtype_Indication (Node1));
kono
parents:
diff changeset
1759
kono
parents:
diff changeset
1760 else
kono
parents:
diff changeset
1761 return Error;
kono
parents:
diff changeset
1762 end if;
kono
parents:
diff changeset
1763
kono
parents:
diff changeset
1764 if Token = Tok_Reverse then
kono
parents:
diff changeset
1765 Scan; -- past REVERSE
kono
parents:
diff changeset
1766 Set_Reverse_Present (Node1, True);
kono
parents:
diff changeset
1767 end if;
kono
parents:
diff changeset
1768
kono
parents:
diff changeset
1769 Set_Name (Node1, P_Name);
kono
parents:
diff changeset
1770 return Node1;
kono
parents:
diff changeset
1771 end P_Iterator_Specification;
kono
parents:
diff changeset
1772
kono
parents:
diff changeset
1773 --------------------------
kono
parents:
diff changeset
1774 -- 5.6 Block Statement --
kono
parents:
diff changeset
1775 --------------------------
kono
parents:
diff changeset
1776
kono
parents:
diff changeset
1777 -- BLOCK_STATEMENT ::=
kono
parents:
diff changeset
1778 -- [block_STATEMENT_IDENTIFIER:]
kono
parents:
diff changeset
1779 -- [declare
kono
parents:
diff changeset
1780 -- DECLARATIVE_PART]
kono
parents:
diff changeset
1781 -- begin
kono
parents:
diff changeset
1782 -- HANDLED_SEQUENCE_OF_STATEMENTS
kono
parents:
diff changeset
1783 -- end [block_IDENTIFIER];
kono
parents:
diff changeset
1784
kono
parents:
diff changeset
1785 -- The parsing of block statements is handled by one of the two functions
kono
parents:
diff changeset
1786 -- P_Declare_Statement or P_Begin_Statement depending on whether or not
kono
parents:
diff changeset
1787 -- a declare section is present
kono
parents:
diff changeset
1788
kono
parents:
diff changeset
1789 -- P_Declare_Statement
kono
parents:
diff changeset
1790
kono
parents:
diff changeset
1791 -- This function parses a block statement with DECLARE present
kono
parents:
diff changeset
1792
kono
parents:
diff changeset
1793 -- The caller has checked that the initial token is DECLARE
kono
parents:
diff changeset
1794
kono
parents:
diff changeset
1795 -- Error recovery: cannot raise Error_Resync
kono
parents:
diff changeset
1796
kono
parents:
diff changeset
1797 function P_Declare_Statement
kono
parents:
diff changeset
1798 (Block_Name : Node_Id := Empty)
kono
parents:
diff changeset
1799 return Node_Id
kono
parents:
diff changeset
1800 is
kono
parents:
diff changeset
1801 Block_Node : Node_Id;
kono
parents:
diff changeset
1802 Created_Name : Node_Id;
kono
parents:
diff changeset
1803
kono
parents:
diff changeset
1804 begin
kono
parents:
diff changeset
1805 Block_Node := New_Node (N_Block_Statement, Token_Ptr);
kono
parents:
diff changeset
1806
kono
parents:
diff changeset
1807 Push_Scope_Stack;
kono
parents:
diff changeset
1808 Scope.Table (Scope.Last).Etyp := E_Name;
kono
parents:
diff changeset
1809 Scope.Table (Scope.Last).Lreq := Present (Block_Name);
kono
parents:
diff changeset
1810 Scope.Table (Scope.Last).Ecol := Start_Column;
kono
parents:
diff changeset
1811 Scope.Table (Scope.Last).Labl := Block_Name;
kono
parents:
diff changeset
1812 Scope.Table (Scope.Last).Sloc := Token_Ptr;
kono
parents:
diff changeset
1813
kono
parents:
diff changeset
1814 Scan; -- past DECLARE
kono
parents:
diff changeset
1815
kono
parents:
diff changeset
1816 if No (Block_Name) then
kono
parents:
diff changeset
1817 Created_Name :=
kono
parents:
diff changeset
1818 Make_Identifier (Sloc (Block_Node), Set_Loop_Block_Name ('B'));
kono
parents:
diff changeset
1819 Set_Comes_From_Source (Created_Name, False);
kono
parents:
diff changeset
1820 Set_Has_Created_Identifier (Block_Node, True);
kono
parents:
diff changeset
1821 Set_Identifier (Block_Node, Created_Name);
kono
parents:
diff changeset
1822 Scope.Table (Scope.Last).Labl := Created_Name;
kono
parents:
diff changeset
1823 else
kono
parents:
diff changeset
1824 Set_Identifier (Block_Node, Block_Name);
kono
parents:
diff changeset
1825 end if;
kono
parents:
diff changeset
1826
kono
parents:
diff changeset
1827 Append_Elmt (Block_Node, Label_List);
kono
parents:
diff changeset
1828 Parse_Decls_Begin_End (Block_Node);
kono
parents:
diff changeset
1829 return Block_Node;
kono
parents:
diff changeset
1830 end P_Declare_Statement;
kono
parents:
diff changeset
1831
kono
parents:
diff changeset
1832 -- P_Begin_Statement
kono
parents:
diff changeset
1833
kono
parents:
diff changeset
1834 -- This function parses a block statement with no DECLARE present
kono
parents:
diff changeset
1835
kono
parents:
diff changeset
1836 -- The caller has checked that the initial token is BEGIN
kono
parents:
diff changeset
1837
kono
parents:
diff changeset
1838 -- Error recovery: cannot raise Error_Resync
kono
parents:
diff changeset
1839
kono
parents:
diff changeset
1840 function P_Begin_Statement
kono
parents:
diff changeset
1841 (Block_Name : Node_Id := Empty)
kono
parents:
diff changeset
1842 return Node_Id
kono
parents:
diff changeset
1843 is
kono
parents:
diff changeset
1844 Block_Node : Node_Id;
kono
parents:
diff changeset
1845 Created_Name : Node_Id;
kono
parents:
diff changeset
1846
kono
parents:
diff changeset
1847 begin
kono
parents:
diff changeset
1848 Block_Node := New_Node (N_Block_Statement, Token_Ptr);
kono
parents:
diff changeset
1849
kono
parents:
diff changeset
1850 Push_Scope_Stack;
kono
parents:
diff changeset
1851 Scope.Table (Scope.Last).Etyp := E_Name;
kono
parents:
diff changeset
1852 Scope.Table (Scope.Last).Lreq := Present (Block_Name);
kono
parents:
diff changeset
1853 Scope.Table (Scope.Last).Ecol := Start_Column;
kono
parents:
diff changeset
1854 Scope.Table (Scope.Last).Labl := Block_Name;
kono
parents:
diff changeset
1855 Scope.Table (Scope.Last).Sloc := Token_Ptr;
kono
parents:
diff changeset
1856
kono
parents:
diff changeset
1857 if No (Block_Name) then
kono
parents:
diff changeset
1858 Created_Name :=
kono
parents:
diff changeset
1859 Make_Identifier (Sloc (Block_Node), Set_Loop_Block_Name ('B'));
kono
parents:
diff changeset
1860 Set_Comes_From_Source (Created_Name, False);
kono
parents:
diff changeset
1861 Set_Has_Created_Identifier (Block_Node, True);
kono
parents:
diff changeset
1862 Set_Identifier (Block_Node, Created_Name);
kono
parents:
diff changeset
1863 Scope.Table (Scope.Last).Labl := Created_Name;
kono
parents:
diff changeset
1864 else
kono
parents:
diff changeset
1865 Set_Identifier (Block_Node, Block_Name);
kono
parents:
diff changeset
1866 end if;
kono
parents:
diff changeset
1867
kono
parents:
diff changeset
1868 Append_Elmt (Block_Node, Label_List);
kono
parents:
diff changeset
1869
kono
parents:
diff changeset
1870 Scope.Table (Scope.Last).Ecol := Start_Column;
kono
parents:
diff changeset
1871 Scope.Table (Scope.Last).Sloc := Token_Ptr;
kono
parents:
diff changeset
1872 Scan; -- past BEGIN
kono
parents:
diff changeset
1873 Set_Handled_Statement_Sequence
kono
parents:
diff changeset
1874 (Block_Node, P_Handled_Sequence_Of_Statements);
kono
parents:
diff changeset
1875 End_Statements (Handled_Statement_Sequence (Block_Node));
kono
parents:
diff changeset
1876 return Block_Node;
kono
parents:
diff changeset
1877 end P_Begin_Statement;
kono
parents:
diff changeset
1878
kono
parents:
diff changeset
1879 -------------------------
kono
parents:
diff changeset
1880 -- 5.7 Exit Statement --
kono
parents:
diff changeset
1881 -------------------------
kono
parents:
diff changeset
1882
kono
parents:
diff changeset
1883 -- EXIT_STATEMENT ::=
kono
parents:
diff changeset
1884 -- exit [loop_NAME] [when CONDITION];
kono
parents:
diff changeset
1885
kono
parents:
diff changeset
1886 -- The caller has checked that the initial token is EXIT
kono
parents:
diff changeset
1887
kono
parents:
diff changeset
1888 -- Error recovery: can raise Error_Resync
kono
parents:
diff changeset
1889
kono
parents:
diff changeset
1890 function P_Exit_Statement return Node_Id is
kono
parents:
diff changeset
1891 Exit_Node : Node_Id;
kono
parents:
diff changeset
1892
kono
parents:
diff changeset
1893 function Missing_Semicolon_On_Exit return Boolean;
kono
parents:
diff changeset
1894 -- This function deals with the following specialized situation
kono
parents:
diff changeset
1895 --
kono
parents:
diff changeset
1896 -- when 'x' =>
kono
parents:
diff changeset
1897 -- exit [identifier]
kono
parents:
diff changeset
1898 -- when 'y' =>
kono
parents:
diff changeset
1899 --
kono
parents:
diff changeset
1900 -- This looks like a messed up EXIT WHEN, when in fact the problem
kono
parents:
diff changeset
1901 -- is a missing semicolon. It is called with Token pointing to the
kono
parents:
diff changeset
1902 -- WHEN token, and returns True if a semicolon is missing before
kono
parents:
diff changeset
1903 -- the WHEN as in the above example.
kono
parents:
diff changeset
1904
kono
parents:
diff changeset
1905 -------------------------------
kono
parents:
diff changeset
1906 -- Missing_Semicolon_On_Exit --
kono
parents:
diff changeset
1907 -------------------------------
kono
parents:
diff changeset
1908
kono
parents:
diff changeset
1909 function Missing_Semicolon_On_Exit return Boolean is
kono
parents:
diff changeset
1910 State : Saved_Scan_State;
kono
parents:
diff changeset
1911
kono
parents:
diff changeset
1912 begin
kono
parents:
diff changeset
1913 if not Token_Is_At_Start_Of_Line then
kono
parents:
diff changeset
1914 return False;
kono
parents:
diff changeset
1915
kono
parents:
diff changeset
1916 elsif Scope.Table (Scope.Last).Etyp /= E_Case then
kono
parents:
diff changeset
1917 return False;
kono
parents:
diff changeset
1918
kono
parents:
diff changeset
1919 else
kono
parents:
diff changeset
1920 Save_Scan_State (State);
kono
parents:
diff changeset
1921 Scan; -- past WHEN
kono
parents:
diff changeset
1922 Scan; -- past token after WHEN
kono
parents:
diff changeset
1923
kono
parents:
diff changeset
1924 if Token = Tok_Arrow then
kono
parents:
diff changeset
1925 Restore_Scan_State (State);
kono
parents:
diff changeset
1926 return True;
kono
parents:
diff changeset
1927 else
kono
parents:
diff changeset
1928 Restore_Scan_State (State);
kono
parents:
diff changeset
1929 return False;
kono
parents:
diff changeset
1930 end if;
kono
parents:
diff changeset
1931 end if;
kono
parents:
diff changeset
1932 end Missing_Semicolon_On_Exit;
kono
parents:
diff changeset
1933
kono
parents:
diff changeset
1934 -- Start of processing for P_Exit_Statement
kono
parents:
diff changeset
1935
kono
parents:
diff changeset
1936 begin
kono
parents:
diff changeset
1937 Exit_Node := New_Node (N_Exit_Statement, Token_Ptr);
kono
parents:
diff changeset
1938 Scan; -- past EXIT
kono
parents:
diff changeset
1939
kono
parents:
diff changeset
1940 if Token = Tok_Identifier then
kono
parents:
diff changeset
1941 Set_Name (Exit_Node, P_Qualified_Simple_Name);
kono
parents:
diff changeset
1942
kono
parents:
diff changeset
1943 elsif Style_Check then
kono
parents:
diff changeset
1944 -- This EXIT has no name, so check that
kono
parents:
diff changeset
1945 -- the innermost loop is unnamed too.
kono
parents:
diff changeset
1946
kono
parents:
diff changeset
1947 Check_No_Exit_Name :
kono
parents:
diff changeset
1948 for J in reverse 1 .. Scope.Last loop
kono
parents:
diff changeset
1949 if Scope.Table (J).Etyp = E_Loop then
kono
parents:
diff changeset
1950 if Present (Scope.Table (J).Labl)
kono
parents:
diff changeset
1951 and then Comes_From_Source (Scope.Table (J).Labl)
kono
parents:
diff changeset
1952 then
kono
parents:
diff changeset
1953 -- Innermost loop in fact had a name, style check fails
kono
parents:
diff changeset
1954
kono
parents:
diff changeset
1955 Style.No_Exit_Name (Scope.Table (J).Labl);
kono
parents:
diff changeset
1956 end if;
kono
parents:
diff changeset
1957
kono
parents:
diff changeset
1958 exit Check_No_Exit_Name;
kono
parents:
diff changeset
1959 end if;
kono
parents:
diff changeset
1960 end loop Check_No_Exit_Name;
kono
parents:
diff changeset
1961 end if;
kono
parents:
diff changeset
1962
kono
parents:
diff changeset
1963 if Token = Tok_When and then not Missing_Semicolon_On_Exit then
kono
parents:
diff changeset
1964 Scan; -- past WHEN
kono
parents:
diff changeset
1965 Set_Condition (Exit_Node, P_Condition);
kono
parents:
diff changeset
1966
kono
parents:
diff changeset
1967 -- Allow IF instead of WHEN, giving error message
kono
parents:
diff changeset
1968
kono
parents:
diff changeset
1969 elsif Token = Tok_If then
kono
parents:
diff changeset
1970 T_When;
kono
parents:
diff changeset
1971 Scan; -- past IF used in place of WHEN
kono
parents:
diff changeset
1972 Set_Condition (Exit_Node, P_Expression_No_Right_Paren);
kono
parents:
diff changeset
1973 end if;
kono
parents:
diff changeset
1974
kono
parents:
diff changeset
1975 TF_Semicolon;
kono
parents:
diff changeset
1976 return Exit_Node;
kono
parents:
diff changeset
1977 end P_Exit_Statement;
kono
parents:
diff changeset
1978
kono
parents:
diff changeset
1979 -------------------------
kono
parents:
diff changeset
1980 -- 5.8 Goto Statement --
kono
parents:
diff changeset
1981 -------------------------
kono
parents:
diff changeset
1982
kono
parents:
diff changeset
1983 -- GOTO_STATEMENT ::= goto label_NAME;
kono
parents:
diff changeset
1984
kono
parents:
diff changeset
1985 -- The caller has checked that the initial token is GOTO (or TO in the
kono
parents:
diff changeset
1986 -- error case where GO and TO were incorrectly separated).
kono
parents:
diff changeset
1987
kono
parents:
diff changeset
1988 -- Error recovery: can raise Error_Resync
kono
parents:
diff changeset
1989
kono
parents:
diff changeset
1990 function P_Goto_Statement return Node_Id is
kono
parents:
diff changeset
1991 Goto_Node : Node_Id;
kono
parents:
diff changeset
1992
kono
parents:
diff changeset
1993 begin
kono
parents:
diff changeset
1994 Goto_Node := New_Node (N_Goto_Statement, Token_Ptr);
kono
parents:
diff changeset
1995 Scan; -- past GOTO (or TO)
kono
parents:
diff changeset
1996 Set_Name (Goto_Node, P_Qualified_Simple_Name_Resync);
kono
parents:
diff changeset
1997 Append_Elmt (Goto_Node, Goto_List);
kono
parents:
diff changeset
1998 No_Constraint;
kono
parents:
diff changeset
1999 TF_Semicolon;
kono
parents:
diff changeset
2000 return Goto_Node;
kono
parents:
diff changeset
2001 end P_Goto_Statement;
kono
parents:
diff changeset
2002
kono
parents:
diff changeset
2003 ---------------------------
kono
parents:
diff changeset
2004 -- Parse_Decls_Begin_End --
kono
parents:
diff changeset
2005 ---------------------------
kono
parents:
diff changeset
2006
kono
parents:
diff changeset
2007 -- This function parses the construct:
kono
parents:
diff changeset
2008
kono
parents:
diff changeset
2009 -- DECLARATIVE_PART
kono
parents:
diff changeset
2010 -- begin
kono
parents:
diff changeset
2011 -- HANDLED_SEQUENCE_OF_STATEMENTS
kono
parents:
diff changeset
2012 -- end [NAME];
kono
parents:
diff changeset
2013
kono
parents:
diff changeset
2014 -- The caller has built the scope stack entry, and created the node to
kono
parents:
diff changeset
2015 -- whose Declarations and Handled_Statement_Sequence fields are to be
kono
parents:
diff changeset
2016 -- set. On return these fields are filled in (except in the case of a
kono
parents:
diff changeset
2017 -- task body, where the handled statement sequence is optional, and may
kono
parents:
diff changeset
2018 -- thus be Empty), and the scan is positioned past the End sequence.
kono
parents:
diff changeset
2019
kono
parents:
diff changeset
2020 -- If the BEGIN is missing, then the parent node is used to help construct
kono
parents:
diff changeset
2021 -- an appropriate missing BEGIN message. Possibilities for the parent are:
kono
parents:
diff changeset
2022
kono
parents:
diff changeset
2023 -- N_Block_Statement declare block
kono
parents:
diff changeset
2024 -- N_Entry_Body entry body
kono
parents:
diff changeset
2025 -- N_Package_Body package body (begin part optional)
kono
parents:
diff changeset
2026 -- N_Subprogram_Body procedure or function body
kono
parents:
diff changeset
2027 -- N_Task_Body task body
kono
parents:
diff changeset
2028
kono
parents:
diff changeset
2029 -- Note: in the case of a block statement, there is definitely a DECLARE
kono
parents:
diff changeset
2030 -- present (because a Begin statement without a DECLARE is handled by the
kono
parents:
diff changeset
2031 -- P_Begin_Statement procedure, which does not call Parse_Decls_Begin_End.
kono
parents:
diff changeset
2032
kono
parents:
diff changeset
2033 -- Error recovery: cannot raise Error_Resync
kono
parents:
diff changeset
2034
kono
parents:
diff changeset
2035 procedure Parse_Decls_Begin_End (Parent : Node_Id) is
kono
parents:
diff changeset
2036 Body_Decl : Node_Id;
kono
parents:
diff changeset
2037 Decls : List_Id;
kono
parents:
diff changeset
2038 Parent_Nkind : Node_Kind;
kono
parents:
diff changeset
2039 Spec_Node : Node_Id;
kono
parents:
diff changeset
2040 HSS : Node_Id;
kono
parents:
diff changeset
2041
kono
parents:
diff changeset
2042 procedure Missing_Begin (Msg : String);
kono
parents:
diff changeset
2043 -- Called to post a missing begin message. In the normal case this is
kono
parents:
diff changeset
2044 -- posted at the start of the current token. A special case arises when
kono
parents:
diff changeset
2045 -- P_Declarative_Items has previously found a missing begin, in which
kono
parents:
diff changeset
2046 -- case we replace the original error message.
kono
parents:
diff changeset
2047
kono
parents:
diff changeset
2048 procedure Set_Null_HSS (Parent : Node_Id);
kono
parents:
diff changeset
2049 -- Construct an empty handled statement sequence and install in Parent
kono
parents:
diff changeset
2050 -- Leaves HSS set to reference the newly constructed statement sequence.
kono
parents:
diff changeset
2051
kono
parents:
diff changeset
2052 -------------------
kono
parents:
diff changeset
2053 -- Missing_Begin --
kono
parents:
diff changeset
2054 -------------------
kono
parents:
diff changeset
2055
kono
parents:
diff changeset
2056 procedure Missing_Begin (Msg : String) is
kono
parents:
diff changeset
2057 begin
kono
parents:
diff changeset
2058 if Missing_Begin_Msg = No_Error_Msg then
kono
parents:
diff changeset
2059 Error_Msg_BC (Msg);
kono
parents:
diff changeset
2060 else
kono
parents:
diff changeset
2061 Change_Error_Text (Missing_Begin_Msg, Msg);
kono
parents:
diff changeset
2062
kono
parents:
diff changeset
2063 -- Purge any messages issued after than, since a missing begin
kono
parents:
diff changeset
2064 -- can cause a lot of havoc, and it is better not to dump these
kono
parents:
diff changeset
2065 -- cascaded messages on the user.
kono
parents:
diff changeset
2066
kono
parents:
diff changeset
2067 Purge_Messages (Get_Location (Missing_Begin_Msg), Prev_Token_Ptr);
kono
parents:
diff changeset
2068 end if;
kono
parents:
diff changeset
2069 end Missing_Begin;
kono
parents:
diff changeset
2070
kono
parents:
diff changeset
2071 ------------------
kono
parents:
diff changeset
2072 -- Set_Null_HSS --
kono
parents:
diff changeset
2073 ------------------
kono
parents:
diff changeset
2074
kono
parents:
diff changeset
2075 procedure Set_Null_HSS (Parent : Node_Id) is
kono
parents:
diff changeset
2076 Null_Stm : Node_Id;
kono
parents:
diff changeset
2077
kono
parents:
diff changeset
2078 begin
kono
parents:
diff changeset
2079 Null_Stm :=
kono
parents:
diff changeset
2080 Make_Null_Statement (Token_Ptr);
kono
parents:
diff changeset
2081 Set_Comes_From_Source (Null_Stm, False);
kono
parents:
diff changeset
2082
kono
parents:
diff changeset
2083 HSS :=
kono
parents:
diff changeset
2084 Make_Handled_Sequence_Of_Statements (Token_Ptr,
kono
parents:
diff changeset
2085 Statements => New_List (Null_Stm));
kono
parents:
diff changeset
2086 Set_Comes_From_Source (HSS, False);
kono
parents:
diff changeset
2087
kono
parents:
diff changeset
2088 Set_Handled_Statement_Sequence (Parent, HSS);
kono
parents:
diff changeset
2089 end Set_Null_HSS;
kono
parents:
diff changeset
2090
kono
parents:
diff changeset
2091 -- Start of processing for Parse_Decls_Begin_End
kono
parents:
diff changeset
2092
kono
parents:
diff changeset
2093 begin
kono
parents:
diff changeset
2094 Decls := P_Declarative_Part;
kono
parents:
diff changeset
2095
kono
parents:
diff changeset
2096 if Ada_Version = Ada_83 then
kono
parents:
diff changeset
2097 Check_Later_Vs_Basic_Declarations (Decls, During_Parsing => True);
kono
parents:
diff changeset
2098 end if;
kono
parents:
diff changeset
2099
kono
parents:
diff changeset
2100 -- Here is where we deal with the case of IS used instead of semicolon.
kono
parents:
diff changeset
2101 -- Specifically, if the last declaration in the declarative part is a
kono
parents:
diff changeset
2102 -- subprogram body still marked as having a bad IS, then this is where
kono
parents:
diff changeset
2103 -- we decide that the IS should really have been a semicolon and that
kono
parents:
diff changeset
2104 -- the body should have been a declaration. Note that if the bad IS
kono
parents:
diff changeset
2105 -- had turned out to be OK (i.e. a decent begin/end was found for it),
kono
parents:
diff changeset
2106 -- then the Bad_Is_Detected flag would have been reset by now.
kono
parents:
diff changeset
2107
kono
parents:
diff changeset
2108 Body_Decl := Last (Decls);
kono
parents:
diff changeset
2109
kono
parents:
diff changeset
2110 if Present (Body_Decl)
kono
parents:
diff changeset
2111 and then Nkind (Body_Decl) = N_Subprogram_Body
kono
parents:
diff changeset
2112 and then Bad_Is_Detected (Body_Decl)
kono
parents:
diff changeset
2113 then
kono
parents:
diff changeset
2114 -- OK, we have the case of a bad IS, so we need to fix up the tree.
kono
parents:
diff changeset
2115 -- What we have now is a subprogram body with attached declarations
kono
parents:
diff changeset
2116 -- and a possible statement sequence.
kono
parents:
diff changeset
2117
kono
parents:
diff changeset
2118 -- First step is to take the declarations that were part of the bogus
kono
parents:
diff changeset
2119 -- subprogram body and append them to the outer declaration chain.
kono
parents:
diff changeset
2120 -- In other words we append them past the body (which we will later
kono
parents:
diff changeset
2121 -- convert into a declaration).
kono
parents:
diff changeset
2122
kono
parents:
diff changeset
2123 Append_List (Declarations (Body_Decl), Decls);
kono
parents:
diff changeset
2124
kono
parents:
diff changeset
2125 -- Now take the handled statement sequence of the bogus body and
kono
parents:
diff changeset
2126 -- set it as the statement sequence for the outer construct. Note
kono
parents:
diff changeset
2127 -- that it may be empty (we specially allowed a missing BEGIN for
kono
parents:
diff changeset
2128 -- a subprogram body marked as having a bad IS -- see below).
kono
parents:
diff changeset
2129
kono
parents:
diff changeset
2130 Set_Handled_Statement_Sequence (Parent,
kono
parents:
diff changeset
2131 Handled_Statement_Sequence (Body_Decl));
kono
parents:
diff changeset
2132
kono
parents:
diff changeset
2133 -- Next step is to convert the old body node to a declaration node
kono
parents:
diff changeset
2134
kono
parents:
diff changeset
2135 Spec_Node := Specification (Body_Decl);
kono
parents:
diff changeset
2136 Change_Node (Body_Decl, N_Subprogram_Declaration);
kono
parents:
diff changeset
2137 Set_Specification (Body_Decl, Spec_Node);
kono
parents:
diff changeset
2138
kono
parents:
diff changeset
2139 -- Final step is to put the declarations for the parent where
kono
parents:
diff changeset
2140 -- they belong, and then fall through the IF to scan out the
kono
parents:
diff changeset
2141 -- END statements.
kono
parents:
diff changeset
2142
kono
parents:
diff changeset
2143 Set_Declarations (Parent, Decls);
kono
parents:
diff changeset
2144
kono
parents:
diff changeset
2145 -- This is the normal case (i.e. any case except the bad IS case)
kono
parents:
diff changeset
2146 -- If we have a BEGIN, then scan out the sequence of statements, and
kono
parents:
diff changeset
2147 -- also reset the expected column for the END to match the BEGIN.
kono
parents:
diff changeset
2148
kono
parents:
diff changeset
2149 else
kono
parents:
diff changeset
2150 Set_Declarations (Parent, Decls);
kono
parents:
diff changeset
2151
kono
parents:
diff changeset
2152 if Token = Tok_Begin then
kono
parents:
diff changeset
2153 if Style_Check then
kono
parents:
diff changeset
2154 Style.Check_Indentation;
kono
parents:
diff changeset
2155 end if;
kono
parents:
diff changeset
2156
kono
parents:
diff changeset
2157 Error_Msg_Col := Scope.Table (Scope.Last).Ecol;
kono
parents:
diff changeset
2158
kono
parents:
diff changeset
2159 if RM_Column_Check
kono
parents:
diff changeset
2160 and then Token_Is_At_Start_Of_Line
kono
parents:
diff changeset
2161 and then Start_Column /= Error_Msg_Col
kono
parents:
diff changeset
2162 then
kono
parents:
diff changeset
2163 Error_Msg_SC ("(style) BEGIN in wrong column, should be@");
kono
parents:
diff changeset
2164
kono
parents:
diff changeset
2165 else
kono
parents:
diff changeset
2166 Scope.Table (Scope.Last).Ecol := Start_Column;
kono
parents:
diff changeset
2167 end if;
kono
parents:
diff changeset
2168
kono
parents:
diff changeset
2169 Scope.Table (Scope.Last).Sloc := Token_Ptr;
kono
parents:
diff changeset
2170 Scan; -- past BEGIN
kono
parents:
diff changeset
2171 Set_Handled_Statement_Sequence (Parent,
kono
parents:
diff changeset
2172 P_Handled_Sequence_Of_Statements);
kono
parents:
diff changeset
2173
kono
parents:
diff changeset
2174 -- No BEGIN present
kono
parents:
diff changeset
2175
kono
parents:
diff changeset
2176 else
kono
parents:
diff changeset
2177 Parent_Nkind := Nkind (Parent);
kono
parents:
diff changeset
2178
kono
parents:
diff changeset
2179 -- A special check for the missing IS case. If we have a
kono
parents:
diff changeset
2180 -- subprogram body that was marked as having a suspicious
kono
parents:
diff changeset
2181 -- IS, and the current token is END, then we simply confirm
kono
parents:
diff changeset
2182 -- the suspicion, and do not require a BEGIN to be present
kono
parents:
diff changeset
2183
kono
parents:
diff changeset
2184 if Parent_Nkind = N_Subprogram_Body
kono
parents:
diff changeset
2185 and then Token = Tok_End
kono
parents:
diff changeset
2186 and then Scope.Table (Scope.Last).Etyp = E_Suspicious_Is
kono
parents:
diff changeset
2187 then
kono
parents:
diff changeset
2188 Scope.Table (Scope.Last).Etyp := E_Bad_Is;
kono
parents:
diff changeset
2189
kono
parents:
diff changeset
2190 -- Otherwise BEGIN is not required for a package body, so we
kono
parents:
diff changeset
2191 -- don't mind if it is missing, but we do construct a dummy
kono
parents:
diff changeset
2192 -- one (so that we have somewhere to set End_Label).
kono
parents:
diff changeset
2193
kono
parents:
diff changeset
2194 -- However if we have something other than a BEGIN which
kono
parents:
diff changeset
2195 -- looks like it might be statements, then we signal a missing
kono
parents:
diff changeset
2196 -- BEGIN for these cases as well. We define "something which
kono
parents:
diff changeset
2197 -- looks like it might be statements" as a token other than
kono
parents:
diff changeset
2198 -- END, EOF, or a token which starts declarations.
kono
parents:
diff changeset
2199
kono
parents:
diff changeset
2200 elsif Parent_Nkind = N_Package_Body
kono
parents:
diff changeset
2201 and then (Token = Tok_End
kono
parents:
diff changeset
2202 or else Token = Tok_EOF
kono
parents:
diff changeset
2203 or else Token in Token_Class_Declk)
kono
parents:
diff changeset
2204 then
kono
parents:
diff changeset
2205 Set_Null_HSS (Parent);
kono
parents:
diff changeset
2206
kono
parents:
diff changeset
2207 -- These are cases in which a BEGIN is required and not present
kono
parents:
diff changeset
2208
kono
parents:
diff changeset
2209 else
kono
parents:
diff changeset
2210 Set_Null_HSS (Parent);
kono
parents:
diff changeset
2211
kono
parents:
diff changeset
2212 -- Prepare to issue error message
kono
parents:
diff changeset
2213
kono
parents:
diff changeset
2214 Error_Msg_Sloc := Scope.Table (Scope.Last).Sloc;
kono
parents:
diff changeset
2215 Error_Msg_Node_1 := Scope.Table (Scope.Last).Labl;
kono
parents:
diff changeset
2216
kono
parents:
diff changeset
2217 -- Now issue appropriate message
kono
parents:
diff changeset
2218
kono
parents:
diff changeset
2219 if Parent_Nkind = N_Block_Statement then
kono
parents:
diff changeset
2220 Missing_Begin ("missing BEGIN for DECLARE#!");
kono
parents:
diff changeset
2221
kono
parents:
diff changeset
2222 elsif Parent_Nkind = N_Entry_Body then
kono
parents:
diff changeset
2223 Missing_Begin ("missing BEGIN for ENTRY#!");
kono
parents:
diff changeset
2224
kono
parents:
diff changeset
2225 elsif Parent_Nkind = N_Subprogram_Body then
kono
parents:
diff changeset
2226 if Nkind (Specification (Parent))
kono
parents:
diff changeset
2227 = N_Function_Specification
kono
parents:
diff changeset
2228 then
kono
parents:
diff changeset
2229 Missing_Begin ("missing BEGIN for function&#!");
kono
parents:
diff changeset
2230 else
kono
parents:
diff changeset
2231 Missing_Begin ("missing BEGIN for procedure&#!");
kono
parents:
diff changeset
2232 end if;
kono
parents:
diff changeset
2233
kono
parents:
diff changeset
2234 -- The case for package body arises only when
kono
parents:
diff changeset
2235 -- we have possible statement junk present.
kono
parents:
diff changeset
2236
kono
parents:
diff changeset
2237 elsif Parent_Nkind = N_Package_Body then
kono
parents:
diff changeset
2238 Missing_Begin ("missing BEGIN for package body&#!");
kono
parents:
diff changeset
2239
kono
parents:
diff changeset
2240 else
kono
parents:
diff changeset
2241 pragma Assert (Parent_Nkind = N_Task_Body);
kono
parents:
diff changeset
2242 Missing_Begin ("missing BEGIN for task body&#!");
kono
parents:
diff changeset
2243 end if;
kono
parents:
diff changeset
2244
kono
parents:
diff changeset
2245 -- Here we pick up the statements after the BEGIN that
kono
parents:
diff changeset
2246 -- should have been present but was not. We don't insist
kono
parents:
diff changeset
2247 -- on statements being present if P_Declarative_Part had
kono
parents:
diff changeset
2248 -- already found a missing BEGIN, since it might have
kono
parents:
diff changeset
2249 -- swallowed a lone statement into the declarative part.
kono
parents:
diff changeset
2250
kono
parents:
diff changeset
2251 if Missing_Begin_Msg /= No_Error_Msg
kono
parents:
diff changeset
2252 and then Token = Tok_End
kono
parents:
diff changeset
2253 then
kono
parents:
diff changeset
2254 null;
kono
parents:
diff changeset
2255 else
kono
parents:
diff changeset
2256 Set_Handled_Statement_Sequence (Parent,
kono
parents:
diff changeset
2257 P_Handled_Sequence_Of_Statements);
kono
parents:
diff changeset
2258 end if;
kono
parents:
diff changeset
2259 end if;
kono
parents:
diff changeset
2260 end if;
kono
parents:
diff changeset
2261 end if;
kono
parents:
diff changeset
2262
kono
parents:
diff changeset
2263 -- Here with declarations and handled statement sequence scanned
kono
parents:
diff changeset
2264
kono
parents:
diff changeset
2265 if Present (Handled_Statement_Sequence (Parent)) then
kono
parents:
diff changeset
2266 End_Statements (Handled_Statement_Sequence (Parent));
kono
parents:
diff changeset
2267 else
kono
parents:
diff changeset
2268 End_Statements;
kono
parents:
diff changeset
2269 end if;
kono
parents:
diff changeset
2270
kono
parents:
diff changeset
2271 -- We know that End_Statements removed an entry from the scope stack
kono
parents:
diff changeset
2272 -- (because it is required to do so under all circumstances). We can
kono
parents:
diff changeset
2273 -- therefore reference the entry it removed one past the stack top.
kono
parents:
diff changeset
2274 -- What we are interested in is whether it was a case of a bad IS.
kono
parents:
diff changeset
2275
kono
parents:
diff changeset
2276 if Scope.Table (Scope.Last + 1).Etyp = E_Bad_Is then
kono
parents:
diff changeset
2277 Error_Msg -- CODEFIX
kono
parents:
diff changeset
2278 ("|IS should be "";""", Scope.Table (Scope.Last + 1).S_Is);
kono
parents:
diff changeset
2279 Set_Bad_Is_Detected (Parent, True);
kono
parents:
diff changeset
2280 end if;
kono
parents:
diff changeset
2281
kono
parents:
diff changeset
2282 end Parse_Decls_Begin_End;
kono
parents:
diff changeset
2283
kono
parents:
diff changeset
2284 -------------------------
kono
parents:
diff changeset
2285 -- Set_Loop_Block_Name --
kono
parents:
diff changeset
2286 -------------------------
kono
parents:
diff changeset
2287
kono
parents:
diff changeset
2288 function Set_Loop_Block_Name (L : Character) return Name_Id is
kono
parents:
diff changeset
2289 begin
kono
parents:
diff changeset
2290 Name_Buffer (1) := L;
kono
parents:
diff changeset
2291 Name_Buffer (2) := '_';
kono
parents:
diff changeset
2292 Name_Len := 2;
kono
parents:
diff changeset
2293 Loop_Block_Count := Loop_Block_Count + 1;
kono
parents:
diff changeset
2294 Add_Nat_To_Name_Buffer (Loop_Block_Count);
kono
parents:
diff changeset
2295 return Name_Find;
kono
parents:
diff changeset
2296 end Set_Loop_Block_Name;
kono
parents:
diff changeset
2297
kono
parents:
diff changeset
2298 ---------------
kono
parents:
diff changeset
2299 -- Then_Scan --
kono
parents:
diff changeset
2300 ---------------
kono
parents:
diff changeset
2301
kono
parents:
diff changeset
2302 procedure Then_Scan is
kono
parents:
diff changeset
2303 begin
kono
parents:
diff changeset
2304 TF_Then;
kono
parents:
diff changeset
2305
kono
parents:
diff changeset
2306 while Token = Tok_Then loop
kono
parents:
diff changeset
2307 Error_Msg_SC -- CODEFIX
kono
parents:
diff changeset
2308 ("redundant THEN");
kono
parents:
diff changeset
2309 TF_Then;
kono
parents:
diff changeset
2310 end loop;
kono
parents:
diff changeset
2311
kono
parents:
diff changeset
2312 if Token = Tok_And or else Token = Tok_Or then
kono
parents:
diff changeset
2313 Error_Msg_SC ("unexpected logical operator");
kono
parents:
diff changeset
2314 Scan; -- past logical operator
kono
parents:
diff changeset
2315
kono
parents:
diff changeset
2316 if (Prev_Token = Tok_And and then Token = Tok_Then)
kono
parents:
diff changeset
2317 or else
kono
parents:
diff changeset
2318 (Prev_Token = Tok_Or and then Token = Tok_Else)
kono
parents:
diff changeset
2319 then
kono
parents:
diff changeset
2320 Scan;
kono
parents:
diff changeset
2321 end if;
kono
parents:
diff changeset
2322
kono
parents:
diff changeset
2323 Discard_Junk_Node (P_Expression);
kono
parents:
diff changeset
2324 end if;
kono
parents:
diff changeset
2325
kono
parents:
diff changeset
2326 if Token = Tok_Then then
kono
parents:
diff changeset
2327 Scan;
kono
parents:
diff changeset
2328 end if;
kono
parents:
diff changeset
2329 end Then_Scan;
kono
parents:
diff changeset
2330
kono
parents:
diff changeset
2331 end Ch5;