Debian Codegraph @

gcc/ada/par.adb

raw
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- P A R --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2025, Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
25
26 with Aspects; use Aspects;
27 with Atree; use Atree;
28 with Casing; use Casing;
29 with Debug; use Debug;
30 with Elists; use Elists;
31 with Errout; use Errout;
32 with Fname; use Fname;
33 with Lib; use Lib;
34 with Namet; use Namet;
35 with Namet.Sp; use Namet.Sp;
36 with Nlists; use Nlists;
37 with Nmake; use Nmake;
38 with Opt; use Opt;
39 with Output; use Output;
40 with Par_SCO; use Par_SCO;
41 with Restrict; use Restrict;
42 with Scans; use Scans;
43 with Scn; use Scn;
44 with Sem_Util; use Sem_Util;
45 with Sinput; use Sinput;
46 with Sinput.L; use Sinput.L;
47 with Sinfo; use Sinfo;
48 with Sinfo.Nodes; use Sinfo.Nodes;
49 with Sinfo.Utils; use Sinfo.Utils;
50 with Snames; use Snames;
51 with Stringt; use Stringt;
52 with Style;
53 with Stylesw; use Stylesw;
54 with Table;
55 with Tbuild; use Tbuild;
56
57 ---------
58 -- Par --
59 ---------
60
61 function Par (Configuration_Pragmas : Boolean) return List_Id is
62
63 Inside_Record_Definition : Boolean := False;
64 -- True within a record definition. Used to control warning for
65 -- redefinition of standard entities (not issued for field names).
66
67 Loop_Block_Count : Nat := 0;
68 -- Counter used for constructing loop/block names (see the routine
69 -- Par.Ch5.Get_Loop_Block_Name).
70
71 Num_Library_Units : Natural := 0;
72 -- Count number of units parsed (relevant only in syntax check only mode,
73 -- since in semantics check mode only a single unit is permitted anyway).
74
75 Save_Config_Attrs : Config_Switches_Type;
76 -- Variable used to save values of config switches while we parse the
77 -- new unit, to be restored on exit for proper recursive behavior.
78
79 Inside_Delta_Aggregate : Boolean := False;
80 -- True within a delta aggregate (but only after the "delta" token has
81 -- been scanned). Used to distinguish syntax errors from syntactically
82 -- correct "deep" delta aggregates (enabled via -gnatX0).
83 Save_Style_Checks : Style_Check_Options;
84 Save_Style_Check : Boolean;
85 -- Variables for storing the original state of whether style checks should
86 -- be active in general and which particular ones should be checked.
87
88 --------------------
89 -- Error Recovery --
90 --------------------
91
92 -- When an error is encountered, a call is made to one of the Error_Msg
93 -- routines to record the error. If the syntax scan is not derailed by the
94 -- error (e.g. a complaint that logical operators are inconsistent in an
95 -- EXPRESSION), then control returns from the Error_Msg call, and the
96 -- parse continues unimpeded.
97
98 -- If on the other hand, the Error_Msg represents a situation from which
99 -- the parser cannot recover locally, the exception Error_Resync is raised
100 -- immediately after the call to Error_Msg. Handlers for Error_Resync
101 -- are located at strategic points to resynchronize the parse. For example,
102 -- when an error occurs in a statement, the handler skips to the next
103 -- semicolon and continues the scan from there.
104
105 -- Each parsing procedure contains a note with the heading "Error recovery"
106 -- which shows if it can propagate the Error_Resync exception. In order
107 -- not to propagate the exception, a procedure must either contain its own
108 -- handler for this exception, or it must not call any other routines which
109 -- propagate the exception.
110
111 -- Note: the arrangement of Error_Resync handlers is such that it should
112 -- never be possible to transfer control through a procedure which made
113 -- an entry in the scope stack, invalidating the contents of the stack.
114
115 Error_Resync : exception;
116 -- Exception raised on error that is not handled locally, see above
117
118 Last_Resync_Point : Source_Ptr;
119 -- The resynchronization routines in Par.Sync run a risk of getting
120 -- stuck in an infinite loop if they do not skip a token, and the caller
121 -- keeps repeating the same resync call. On the other hand, if they skip
122 -- a token unconditionally, some recovery opportunities are missed. The
123 -- variable Last_Resync_Point records the token location previously set
124 -- by a Resync call, and if a subsequent Resync call occurs at the same
125 -- location, then the Resync routine does guarantee to skip a token.
126
127 --------------------------------------------
128 -- Handling Semicolon Used in Place of IS --
129 --------------------------------------------
130
131 -- The following global variables are used in handling the error situation
132 -- of using a semicolon in place of IS in a subprogram declaration as in:
133
134 -- procedure X (Y : Integer);
135 -- Q : Integer;
136 -- begin
137 -- ...
138 -- end;
139
140 -- The two contexts in which this can appear are at the outer level, and
141 -- within a declarative region. At the outer level, we know something is
142 -- wrong as soon as we see the Q (or begin, if there are no declarations),
143 -- and we can immediately decide that the semicolon should have been IS.
144
145 -- The situation in a declarative region is more complex. The declaration
146 -- of Q could belong to the outer region, and we do not know that we have
147 -- an error until we hit the begin. It is still not clear at this point
148 -- from a syntactic point of view that something is wrong, because the
149 -- begin could belong to the enclosing subprogram or package. However, we
150 -- can incorporate a bit of semantic knowledge and note that the body of
151 -- X is missing, so we definitely DO have an error. We diagnose this error
152 -- as semicolon in place of IS on the subprogram line.
153
154 -- There are two styles for this diagnostic. If the begin immediately
155 -- follows the semicolon, then we can place a flag (IS expected) right
156 -- on the semicolon. Otherwise we do not detect the error until we hit
157 -- the begin which refers back to the line with the semicolon.
158
159 -- To control the process in the second case, the following global
160 -- variables are set to indicate that we have a subprogram declaration
161 -- whose body is required and has not yet been found. The prefix SIS
162 -- stands for "Subprogram IS" handling.
163
164 SIS_Entry_Active : Boolean := False;
165 -- Set True to indicate that an entry is active (i.e. that a subprogram
166 -- declaration has been encountered, and no body for this subprogram
167 -- has been encountered). The remaining variables other than
168 -- SIS_Aspect_Import_Seen are valid only if this is True.
169
170 SIS_Aspect_Import_Seen : Boolean := False;
171 -- If this is True when a subprogram declaration has been encountered, we
172 -- do not set SIS_Entry_Active, because the Import means there is no body.
173 -- Set False at the start of P_Subprogram, set True when an Import aspect
174 -- specification is seen, and used when P_Subprogram finds a subprogram
175 -- declaration. This is necessary because the aspects are parsed before
176 -- we know we have a subprogram declaration.
177
178 SIS_Labl : Node_Id;
179 -- Subprogram designator
180
181 SIS_Sloc : Source_Ptr;
182 -- Source location of FUNCTION/PROCEDURE keyword
183
184 SIS_Ecol : Column_Number;
185 -- Column number of FUNCTION/PROCEDURE keyword
186
187 SIS_Semicolon_Sloc : Source_Ptr;
188 -- Source location of semicolon at end of subprogram declaration
189
190 SIS_Declaration_Node : Node_Id;
191 -- Pointer to tree node for subprogram declaration
192
193 SIS_Missing_Semicolon_Message : Error_Msg_Id;
194 -- Used to save message ID of missing semicolon message (which will be
195 -- modified to missing IS if necessary). Set to No_Error_Msg in the
196 -- normal (non-error) case.
197
198 -- Five things can happen to an active SIS entry
199
200 -- 1. If a BEGIN is encountered with an SIS entry active, then we have
201 -- exactly the situation in which we know the body of the subprogram is
202 -- missing. After posting an error message, we change the spec to a body,
203 -- rechaining the declarations that intervened between the spec and BEGIN.
204
205 -- 2. Another subprogram declaration or body is encountered. In this
206 -- case the entry gets overwritten with the information for the new
207 -- subprogram declaration. We don't catch some nested cases this way,
208 -- but it doesn't seem worth the effort.
209
210 -- 3. A nested declarative region (e.g. package declaration or package
211 -- body) is encountered. The SIS active indication is reset at the start
212 -- of such a nested region. Again, like case 2, this causes us to miss
213 -- some nested cases, but it doesn't seen worth the effort to stack and
214 -- unstack the SIS information. Maybe we will reconsider this if we ever
215 -- get a complaint about a missed case.
216
217 -- 4. We encounter a valid pragma INTERFACE or IMPORT that effectively
218 -- supplies the missing body. In this case we reset the entry.
219
220 -- 5. We encounter the end of the declarative region without encountering
221 -- a BEGIN first. In this situation we simply reset the entry. We know
222 -- that there is a missing body, but it seems more reasonable to let the
223 -- later semantic checking discover this.
224
225 ----------------------------------------------------
226 -- Handling of Reserved Words Used as Identifiers --
227 ----------------------------------------------------
228
229 -- Note: throughout the parser, the terms reserved word and keyword are
230 -- used interchangeably to refer to the same set of reserved keywords
231 -- (including until, protected, etc).
232
233 -- If a reserved word is used in place of an identifier, the parser where
234 -- possible tries to recover gracefully. In particular, if the keyword is
235 -- clearly spelled using identifier casing, e.g. Until in a source program
236 -- using mixed case identifiers and lower case keywords, then the keyword
237 -- is treated as an identifier if it appears in a place where an identifier
238 -- is required.
239
240 -- The situation is more complex if the keyword is spelled with normal
241 -- keyword casing. In this case, the parser is more reluctant to consider
242 -- it to be intended as an identifier, unless it has some further
243 -- confirmation.
244
245 -- In the case of an identifier appearing in the identifier list of a
246 -- declaration, the appearance of a comma or colon right after the keyword
247 -- on the same line is taken as confirmation. For an enumeration literal,
248 -- a comma or right paren right after the identifier is also treated as
249 -- adequate confirmation.
250
251 -- The following type is used in calls to Is_Reserved_Identifier and
252 -- also to P_Defining_Identifier and P_Identifier. The default for all
253 -- these functions is that reserved words in reserved word case are not
254 -- considered to be reserved identifiers. The Id_Check value indicates
255 -- tokens, which if they appear immediately after the identifier, are
256 -- taken as confirming that the use of an identifier was expected
257
258 type Id_Check is
259 (None,
260 -- Default, no special token test
261
262 C_Comma_Right_Paren,
263 -- Consider as identifier if followed by comma or right paren
264
265 C_Comma_Colon,
266 -- Consider as identifier if followed by comma or colon
267
268 C_Do,
269 -- Consider as identifier if followed by DO
270
271 C_Dot,
272 -- Consider as identifier if followed by period
273
274 C_Greater_Greater,
275 -- Consider as identifier if followed by >>
276
277 C_In,
278 -- Consider as identifier if followed by IN
279
280 C_Is,
281 -- Consider as identifier if followed by IS
282
283 C_Left_Paren_Semicolon,
284 -- Consider as identifier if followed by left paren or semicolon
285
286 C_Use,
287 -- Consider as identifier if followed by USE
288
289 C_Vertical_Bar_Arrow);
290 -- Consider as identifier if followed by | or =>
291
292 --------------------------------------------
293 -- Handling IS Used in Place of Semicolon --
294 --------------------------------------------
295
296 -- This is a somewhat trickier situation, and we can't catch it in all
297 -- cases, but we do our best to detect common situations resulting from
298 -- a "cut and paste" operation which forgets to change the IS to semicolon.
299 -- Consider the following example:
300
301 -- package body X is
302 -- procedure A;
303 -- procedure B is
304 -- procedure C;
305 -- ...
306 -- procedure D is
307 -- begin
308 -- ...
309 -- end;
310 -- begin
311 -- ...
312 -- end;
313
314 -- The trouble is that the section of text from PROCEDURE B through END;
315 -- constitutes a valid procedure body, and the danger is that we find out
316 -- far too late that something is wrong (indeed most compilers will behave
317 -- uncomfortably on the above example).
318
319 -- We have two approaches to helping to control this situation. First we
320 -- make every attempt to avoid swallowing the last END; if we can be sure
321 -- that some error will result from doing so. In particular, we won't
322 -- accept the END; unless it is exactly correct (in particular it must not
323 -- have incorrect name tokens), and we won't accept it if it is immediately
324 -- followed by end of file, WITH or SEPARATE (all tokens that unmistakeably
325 -- signal the start of a compilation unit, and which therefore allow us to
326 -- reserve the END; for the outer level.) For more details on this aspect
327 -- of the handling, see package Par.Endh.
328
329 -- If we can avoid eating up the END; then the result in the absence of
330 -- any additional steps would be to post a missing END referring back to
331 -- the subprogram with the bogus IS. Similarly, if the enclosing package
332 -- has no BEGIN, then the result is a missing BEGIN message, which again
333 -- refers back to the subprogram header.
334
335 -- Such an error message is not too bad (it's already a big improvement
336 -- over what many parsers do), but it's not ideal, because the declarations
337 -- following the IS have been absorbed into the wrong scope. In the above
338 -- case, this could result for example in a bogus complaint that the body
339 -- of D was missing from the package.
340
341 -- To catch at least some of these cases, we take the following additional
342 -- steps. First, a subprogram body is marked as having a suspicious IS if
343 -- the declaration line is followed by a line which starts with a symbol
344 -- that can start a declaration in the same column, or to the left of the
345 -- column in which the FUNCTION or PROCEDURE starts (normal style is to
346 -- indent any declarations which really belong a subprogram). If such a
347 -- subprogram encounters a missing BEGIN or missing END, then we decide
348 -- that the IS should have been a semicolon, and the subprogram body node
349 -- is marked (by setting the Bad_Is_Detected flag true. Note that we do
350 -- not do this for library level procedures, only for nested procedures,
351 -- since for library level procedures, we must have a body.
352
353 -- The processing for a declarative part checks to see if the last
354 -- declaration scanned is marked in this way, and if it is, the tree
355 -- is modified to reflect the IS being interpreted as a semicolon.
356
357 ---------------------------------------------------
358 -- Parser Type Definitions and Control Variables --
359 ---------------------------------------------------
360
361 -- The following variable and associated type declaration are used by the
362 -- expression parsing routines to return more detailed information about
363 -- the categorization of a parsed expression.
364
365 type Expr_Form_Type is (
366 EF_Simple_Name, -- Simple name, i.e. possibly qualified identifier
367 EF_Name, -- Simple expression which could also be a name
368 EF_Simple, -- Simple expression which is not call or name
369 EF_Range_Attr, -- Range attribute reference
370 EF_Non_Simple); -- Expression that is not a simple expression
371
372 Expr_Form : Expr_Form_Type;
373
374 -- The following type is used by P_Subprogram, P_Package, to indicate which
375 -- of several possibilities is acceptable.
376
377 type Pf_Rec is record
378 Spcn : Boolean; -- True if specification OK
379 Decl : Boolean; -- True if declaration OK
380 Gins : Boolean; -- True if generic instantiation OK
381 Pbod : Boolean; -- True if proper body OK
382 Rnam : Boolean; -- True if renaming declaration OK
383 Stub : Boolean; -- True if body stub OK
384 Pexp : Boolean; -- True if parameterized expression OK
385 end record;
386 pragma Pack (Pf_Rec);
387
388 function T return Boolean renames True;
389 function F return Boolean renames False;
390
391 Pf_Decl_Gins_Pbod_Rnam_Stub_Pexp : constant Pf_Rec := (F, T, T, T, T, T, T);
392 Pf_Decl_Pexp : constant Pf_Rec := (F, T, F, F, F, F, T);
393 Pf_Decl_Gins_Pbod_Rnam_Pexp : constant Pf_Rec := (F, T, T, T, T, F, T);
394 Pf_Decl_Pbod_Pexp : constant Pf_Rec := (F, T, F, T, F, F, T);
395 Pf_Pbod_Pexp : constant Pf_Rec := (F, F, F, T, F, F, T);
396 Pf_Spcn : constant Pf_Rec := (T, F, F, F, F, F, F);
397 -- The above are the only allowed values of Pf_Rec arguments
398
399 type SS_Rec is record
400 Eftm : Boolean; -- ELSIF can terminate sequence
401 Eltm : Boolean; -- ELSE can terminate sequence
402 Extm : Boolean; -- EXCEPTION can terminate sequence
403 Fitm : Boolean; -- FINALLY can terminate sequence
404 Ortm : Boolean; -- OR can terminate sequence
405 Sreq : Boolean; -- at least one statement required
406 Tatm : Boolean; -- THEN ABORT can terminate sequence
407 Whtm : Boolean; -- WHEN can terminate sequence
408 Unco : Boolean; -- Unconditional terminate after one statement
409 end record;
410 pragma Pack (SS_Rec);
411
412 SS_Eftm_Eltm_Sreq : constant SS_Rec := (T, T, F, F, F, T, F, F, F);
413 SS_Eltm_Ortm_Tatm : constant SS_Rec := (F, T, F, F, T, F, T, F, F);
414 SS_Extm_Fitm_Sreq : constant SS_Rec := (F, F, T, T, F, T, F, F, F);
415 SS_None : constant SS_Rec := (F, F, F, F, F, F, F, F, F);
416 SS_Ortm_Sreq : constant SS_Rec := (F, F, F, F, T, T, F, F, F);
417 SS_Sreq : constant SS_Rec := (F, F, F, F, F, T, F, F, F);
418 SS_Sreq_Whtm : constant SS_Rec := (F, F, F, F, F, T, F, T, F);
419 SS_Sreq_Fitm_Whtm : constant SS_Rec := (F, F, F, T, F, T, F, T, F);
420 SS_Whtm : constant SS_Rec := (F, F, F, F, F, F, F, T, F);
421 SS_Unco : constant SS_Rec := (F, F, F, F, F, F, F, F, T);
422
423 Goto_List : Elist_Id;
424 -- List of goto nodes appearing in the current compilation. Used to
425 -- recognize natural loops and convert them into bona fide loops for
426 -- optimization purposes.
427
428 Label_List : Elist_Id;
429 -- List of label nodes for labels appearing in the current compilation.
430 -- Used by Par.Labl to construct the corresponding implicit declarations.
431
432 -----------------
433 -- Scope Table --
434 -----------------
435
436 -- The scope table, also referred to as the scope stack, is used to record
437 -- the current scope context. It is organized as a stack, with inner nested
438 -- entries corresponding to higher entries on the stack. An entry is made
439 -- when the parser encounters the opening of a nested construct (such as a
440 -- record, task, package etc.), and then package Par.Endh uses this stack
441 -- to deal with END lines (including properly dealing with END nesting
442 -- errors).
443
444 type SS_End_Type is
445 -- Type of end entry required for this scope. The last two entries are
446 -- used only in the subprogram body case to mark the case of a suspicious
447 -- IS, or a bad IS (i.e. suspicions confirmed by missing BEGIN or END).
448 -- See separate section on dealing with IS used in place of semicolon.
449 -- Note that for many purposes E_Name, E_Suspicious_Is and E_Bad_Is are
450 -- treated the same (E_Suspicious_Is and E_Bad_Is are simply special cases
451 -- of E_Name). They are placed at the end of the enumeration so that a
452 -- test for >= E_Name catches all three cases efficiently.
453
454 (E_Dummy, -- dummy entry at outer level
455 E_Case, -- END CASE;
456 E_If, -- END IF;
457 E_Loop, -- END LOOP;
458 E_Record, -- END RECORD;
459 E_Return, -- END RETURN;
460 E_Select, -- END SELECT;
461 E_Name, -- END [name];
462 E_Suspicious_Is, -- END [name]; (case of suspicious IS)
463 E_Bad_Is); -- END [name]; (case of bad IS)
464
465 -- The following describes a single entry in the scope table
466
467 type Scope_Table_Entry is record
468 Etyp : SS_End_Type;
469 -- Type of end entry, as per above description
470
471 Lreq : Boolean;
472 -- A flag indicating whether the label, if present, is required to
473 -- appear on the end line. It is referenced only in the case of Etyp is
474 -- equal to E_Name or E_Suspicious_Is where the name may or may not be
475 -- required (yes for labeled block, no in other cases). Note that for
476 -- all cases except begin, the question of whether a label is required
477 -- can be determined from the other fields (for loop, it is required if
478 -- it is present, and for the other constructs it is never required or
479 -- allowed).
480
481 Ecol : Column_Number;
482 -- Contains the absolute column number (with tabs expanded) of the
483 -- expected column of the end assuming normal Ada indentation usage. If
484 -- the RM_Column_Check mode is set, this value is used for generating
485 -- error messages about indentation. Otherwise it is used only to
486 -- control heuristic error recovery actions. This value is zero origin.
487
488 Labl : Node_Id;
489 -- This field is used to provide the name of the construct being parsed
490 -- and indirectly its kind. For loops and blocks, the field contains the
491 -- source name or the generated one. For package specifications, bodies,
492 -- subprogram specifications and bodies the field holds the
493 -- corresponding program unit name. For task declarations and bodies,
494 -- protected types and bodies, and accept statements the field hold the
495 -- name of the type or operation. For if-statements, case-statements,
496 -- return statements, and selects, the field is initialized to Error.
497
498 -- Note: this is a bit of an odd (mis)use of Error, since there is no
499 -- Error, but we use this value as a place holder to indicate that it
500 -- is an error to have a label on the end line.
501
502 -- Whenever the field is a name, it is attached to the parent node of
503 -- the construct being parsed. Thus the parent node indicates the kind
504 -- of construct whose parse tree is being built. This is used in error
505 -- recovery.
506
507 Decl : List_Id;
508 -- Points to the list of declarations (i.e. the declarative part)
509 -- associated with this construct. It is set only in the END [name]
510 -- cases, and is set to No_List for all other cases which do not have a
511 -- declarative unit associated with them. This is used for determining
512 -- the proper location for implicit label declarations.
513
514 Node : Node_Id;
515 -- Empty except in the case of entries for IF and CASE statements, in
516 -- which case it contains the N_If_Statement or N_Case_Statement node.
517 -- This is used for setting the End_Span field.
518
519 Sloc : Source_Ptr;
520 -- Source location of the opening token of the construct. This is used
521 -- to refer back to this line in error messages (such as missing or
522 -- incorrect end lines). The Sloc field is not used, and is not set, if
523 -- a label is present (the Labl field provides the text name of the
524 -- label in this case, which is fine for error messages).
525
526 S_Is : Source_Ptr;
527 -- S_Is is relevant only if Etyp is set to E_Suspicious_Is or E_Bad_Is.
528 -- It records the location of the IS that is considered to be
529 -- suspicious.
530
531 Junk : Boolean;
532 -- A boolean flag that is set true if the opening entry is the dubious
533 -- result of some prior error, e.g. a record entry where the record
534 -- keyword was missing. It is used to suppress the issuing of a
535 -- corresponding junk complaint about the end line (we do not want
536 -- to complain about a missing end record when there was no record).
537 end record;
538
539 -- The following declares the scope table itself. The Last field is the
540 -- stack pointer, so that Scope.Table (Scope.Last) is the top entry. The
541 -- oldest entry, at Scope_Stack (0), is a dummy entry with Etyp set to
542 -- E_Dummy, and the other fields undefined. This dummy entry ensures that
543 -- Scope_Stack (Scope_Stack_Ptr).Etyp can always be tested, and that the
544 -- scope stack pointer is always in range.
545
546 package Scope is new Table.Table (
547 Table_Component_Type => Scope_Table_Entry,
548 Table_Index_Type => Int,
549 Table_Low_Bound => 0,
550 Table_Initial => 50,
551 Table_Increment => 100,
552 Table_Name => "Scope");
553
554 type Scope_Table_Entry_Ptr is access all Scope_Table_Entry;
555
556 function Scopes (Index : Int) return Scope_Table_Entry_Ptr;
557 -- Return the indicated Scope_Table_Entry. We use a pointer for
558 -- efficiency. Callers should not save the pointer, but should do things
559 -- like Scopes (Scope.Last).Something. Note that there is one place in
560 -- Par.Ch5 that indexes the stack out of bounds, and can't call this.
561
562 function Scopes (Index : Int) return Scope_Table_Entry_Ptr is
563 begin
564 pragma Assert (Index in Scope.First .. Scope.Last);
565 return Scope.Table (Index)'Unrestricted_Access;
566 end Scopes;
567
568 ------------------------------------------
569 -- Table for Handling Suspicious Labels --
570 ------------------------------------------
571
572 -- This is a special data structure which is used to deal very specifically
573 -- with the following error case
574
575 -- label;
576 -- loop
577 -- ...
578 -- end loop label;
579
580 -- Similar cases apply to FOR, WHILE, DECLARE, or BEGIN
581
582 -- In each case the opening line looks like a procedure call because of
583 -- the semicolon. And the end line looks illegal because of an unexpected
584 -- label. If we did nothing special, we would just diagnose the label on
585 -- the end as unexpected. But that does not help point to the real error
586 -- which is that the semicolon after label should be a colon.
587
588 -- To deal with this, we build an entry in the Suspicious_Labels table
589 -- whenever we encounter an identifier followed by a semicolon, followed
590 -- by one of LOOP, FOR, WHILE, DECLARE, BEGIN. Then this entry is used to
591 -- issue the right message when we hit the END that confirms that this was
592 -- a bad label.
593
594 type Suspicious_Label_Entry is record
595 Proc_Call : Node_Id;
596 -- Node for the procedure call statement built for the label; construct
597
598 Semicolon_Loc : Source_Ptr;
599 -- Location of the possibly wrong semicolon
600
601 Start_Token : Source_Ptr;
602 -- Source location of the LOOP, FOR, WHILE, DECLARE, BEGIN token
603 end record;
604
605 package Suspicious_Labels is new Table.Table (
606 Table_Component_Type => Suspicious_Label_Entry,
607 Table_Index_Type => Int,
608 Table_Low_Bound => 1,
609 Table_Initial => 50,
610 Table_Increment => 100,
611 Table_Name => "Suspicious_Labels");
612
613 -- Now when we are about to issue a message complaining about an END label
614 -- that should not be there because it appears to end a construct that has
615 -- no label, we first search the suspicious labels table entry, using the
616 -- source location stored in the scope table as a key. If we find a match,
617 -- then we check that the label on the end matches the name in the call,
618 -- and if so, we issue a message saying the semicolon should be a colon.
619
620 -- Quite a bit of work, but really helpful in the case where it helps, and
621 -- the need for this is based on actual experience with tracking down this
622 -- kind of error (the eye often easily mistakes semicolon for colon).
623
624 -- Note: we actually have enough information to patch up the tree, but
625 -- this may not be worth the effort. Also we could deal with the same
626 -- situation for EXIT with a label, but for now don't bother with that.
627
628 Current_Assign_Node : Node_Id := Empty;
629 -- This is the node of the current assignment statement being compiled.
630 -- It is used to record the presence of target_names on its RHS. This
631 -- context-dependent trick simplifies the analysis of such nodes, where
632 -- the RHS must first be analyzed with expansion disabled.
633
634 ---------------------------------
635 -- Parsing Routines by Chapter --
636 ---------------------------------
637
638 -- Uncommented declarations in this section simply parse the construct
639 -- corresponding to their name, and return an ID value for the Node or
640 -- List that is created.
641
642 -------------
643 -- Par.Ch2 --
644 -------------
645
646 package Ch2 is
647 function P_Pragma (Skipping : Boolean := False) return Node_Id;
648 -- Scan out a pragma. If Skipping is True, then the caller is skipping
649 -- the pragma in the context of illegal placement (this is used to avoid
650 -- some junk cascaded messages). Some pragmas must be dealt with during
651 -- the parsing phase (e.g. pragma Page, since we can generate a listing
652 -- in syntax only mode). It is possible that the parser uses the rescan
653 -- logic (using Save/Restore_Scan_State) with the effect of calling this
654 -- procedure more than once for the same pragma. All parse-time pragma
655 -- handling must be prepared to handle such multiple calls correctly.
656
657 function P_Identifier
658 (C : Id_Check := None;
659 Force_Msg : Boolean := False) return Node_Id;
660 -- Scans out an identifier. The parameter C determines the treatment
661 -- of reserved identifiers. See declaration of Id_Check for details.
662
663 -- An appropriate error message, pointing to the token, is also issued
664 -- if either this is the first occurrence of misuse of this identifier,
665 -- or if Force_Msg is True.
666
667 function P_Interpolated_String_Literal return Node_Id;
668
669 function P_Pragmas_Opt return List_Id;
670 -- This function scans for a sequence of pragmas in other than a
671 -- declaration sequence or statement sequence context. All pragmas
672 -- can appear except pragmas Assert and Debug, which are only allowed
673 -- in a declaration or statement sequence context.
674
675 procedure P_Pragmas_Misplaced;
676 -- Skips misplaced pragmas with a complaint
677
678 procedure P_Pragmas_Opt (List : List_Id);
679 -- Parses optional pragmas and appends them to the List
680 end Ch2;
681
682 -------------
683 -- Par.Ch3 --
684 -------------
685
686 package Ch3 is
687 Missing_Begin_Msg : Error_Msg_Id;
688 -- This variable is set by a call to P_Declarative_Part. Normally it
689 -- is set to No_Error_Msg, indicating that no special processing is
690 -- required by the caller. The special case arises when a statement
691 -- is found in the sequence of declarations. In this case the Id of
692 -- the message issued ("declaration expected") is preserved in this
693 -- variable, then the caller can change it to an appropriate missing
694 -- begin message if indeed the BEGIN is missing.
695
696 function P_Array_Type_Definition return Node_Id;
697 function P_Constraint_Opt return Node_Id;
698 function P_Declarative_Part return List_Id;
699 function P_Discrete_Choice_List return List_Id;
700 function P_Discrete_Range return Node_Id;
701 function P_Discrete_Subtype_Definition return Node_Id;
702 function P_Known_Discriminant_Part_Opt return List_Id;
703 function P_Signed_Integer_Type_Definition return Node_Id;
704 function P_Range return Node_Id;
705 function P_Range_Constraint return Node_Id;
706 function P_Record_Definition return Node_Id;
707 function P_Subtype_Mark return Node_Id;
708 function P_Subtype_Mark_Resync return Node_Id;
709 function P_Unknown_Discriminant_Part_Opt return Boolean;
710
711 procedure P_Declarative_Items
712 (Decls : List_Id;
713 Declare_Expression : Boolean;
714 In_Spec : Boolean;
715 In_Statements : Boolean);
716 -- Parses a sequence of zero or more declarative items, and appends them
717 -- to Decls. Done indicates whether or not there might be additional
718 -- declarative items to parse. If Done is True, then there are no more
719 -- to parse; otherwise there might be more.
720 --
721 -- Declare_Expression is true if we are parsing a declare_expression, in
722 -- which case we want to suppress certain style checking.
723 --
724 -- In_Spec is true if we are scanning a package declaration, and is used
725 -- to generate an appropriate message if a statement is encountered in
726 -- such a context.
727 --
728 -- In_Statements is true if we are called to parse declarative items in
729 -- a sequence of statements. In this case, we do not give an error upon
730 -- encountering a statement, but return to the caller with Done = True,
731 -- so the caller can resume parsing statements.
732
733 function P_Basic_Declarative_Items
734 (Declare_Expression : Boolean) return List_Id;
735 -- Used to parse the declarative items in a package visible or
736 -- private part (in which case Declare_Expression is False), and
737 -- the declare_items of a declare_expression (in which case
738 -- Declare_Expression is True). Declare_Expression is used to
739 -- affect the wording of error messages, and to control style
740 -- checking.
741
742 function P_Access_Definition
743 (Null_Exclusion_Present : Boolean) return Node_Id;
744 -- Ada 2005 (AI-231/AI-254): The caller parses the null-exclusion part
745 -- and indicates if it was present
746
747 function P_Access_Type_Definition
748 (Header_Already_Parsed : Boolean := False) return Node_Id;
749 -- Ada 2005 (AI-254): The formal is used to indicate if the caller has
750 -- parsed the null_exclusion part. In this case the caller has also
751 -- removed the ACCESS token
752
753 procedure P_Component_Items (Decls : List_Id);
754 -- Scan out one or more component items and append them to the given
755 -- list. Only scans out more than one declaration in the case where the
756 -- source has a single declaration with multiple defining identifiers.
757
758 function P_Defining_Identifier (C : Id_Check := None) return Node_Id;
759 -- Scan out a defining identifier. The parameter C controls the
760 -- treatment of errors in case a reserved word is scanned. See the
761 -- declaration of this type for details.
762
763 function P_Interface_Type_Definition
764 (Abstract_Present : Boolean) return Node_Id;
765 -- Ada 2005 (AI-251): Parse the interface type definition part. Abstract
766 -- Present indicates if the reserved word "abstract" has been previously
767 -- found. It is used to report an error message because interface types
768 -- are by definition abstract tagged. We generate a record_definition
769 -- node if the list of interfaces is empty; otherwise we generate a
770 -- derived_type_definition node (the first interface in this list is the
771 -- ancestor interface).
772
773 function P_Null_Exclusion
774 (Allow_Anonymous_In_95 : Boolean := False) return Boolean;
775 -- Ada 2005 (AI-231): Parse the null-excluding part. A True result
776 -- indicates that the null-excluding part was present.
777 --
778 -- Allow_Anonymous_In_95 is True if we are in a context that allows
779 -- anonymous access types in Ada 95, in which case "not null" is legal
780 -- if it precedes "access".
781
782 function P_Subtype_Indication
783 (Not_Null_Present : Boolean := False) return Node_Id;
784 -- Ada 2005 (AI-231): The flag Not_Null_Present indicates that the
785 -- null-excluding part has been scanned out and it was present.
786
787 function P_Range_Or_Subtype_Mark
788 (Allow_Simple_Expression : Boolean := False) return Node_Id;
789 -- Scans out a range or subtype mark, and also permits a general simple
790 -- expression if Allow_Simple_Expression is set to True.
791
792 function Init_Expr_Opt (P : Boolean := False) return Node_Id;
793 -- If an initialization expression is present (:= expression), then
794 -- it is scanned out and returned, otherwise Empty is returned if no
795 -- initialization expression is present. This procedure also handles
796 -- certain common error cases cleanly. The parameter P indicates if
797 -- a right paren can follow the expression (default = no right paren
798 -- allowed).
799
800 procedure Skip_Declaration (S : List_Id);
801 -- Used when scanning statements to skip past a misplaced declaration
802 -- The declaration is scanned out and appended to the given list.
803 -- Token is known to be a declaration token (in Token_Class_Declk)
804 -- on entry, so there definition is a declaration to be scanned.
805
806 function P_Subtype_Indication
807 (Subtype_Mark : Node_Id;
808 Not_Null_Present : Boolean := False) return Node_Id;
809 -- This version of P_Subtype_Indication is called when the caller has
810 -- already scanned out the subtype mark which is passed as a parameter.
811 -- Ada 2005 (AI-231): The flag Not_Null_Present indicates that the
812 -- null-excluding part has been scanned out and it was present.
813
814 function P_Subtype_Mark_Attribute (Type_Node : Node_Id) return Node_Id;
815 -- Parse a subtype mark attribute. The caller has already parsed the
816 -- subtype mark, which is passed in as the argument, and has checked
817 -- that the current token is apostrophe.
818 end Ch3;
819
820 -------------
821 -- Par.Ch4 --
822 -------------
823
824 package Ch4 is
825 function P_Aggregate return Node_Id;
826 function P_Expression return Node_Id;
827 function P_Expression_Or_Range_Attribute return Node_Id;
828 function P_Function_Name return Node_Id;
829 function P_Name return Node_Id;
830 function P_Qualified_Simple_Name return Node_Id;
831 function P_Qualified_Simple_Name_Resync return Node_Id;
832 function P_Simple_Expression return Node_Id;
833 function P_Simple_Expression_Or_Range_Attribute return Node_Id;
834
835 function P_Expression_If_OK return Node_Id;
836 -- Scans out an expression allowing an unparenthesized case expression,
837 -- if expression, or quantified expression to appear without enclosing
838 -- parentheses. However, if such an expression is not preceded by a left
839 -- paren, and followed by a right paren, an error message will be output
840 -- noting that parenthesization is required.
841
842 function P_Expression_No_Right_Paren return Node_Id;
843 -- Scans out an expression in contexts where the expression cannot be
844 -- terminated by a right paren (gives better error recovery if an errant
845 -- right paren is found after the expression).
846
847 function P_Expression_Or_Range_Attribute_If_OK return Node_Id;
848 -- Scans out an expression or range attribute where a conditional
849 -- expression is permitted to appear without surrounding parentheses.
850 -- However, if such an expression is not preceded by a left paren, and
851 -- followed by a right paren, an error message will be output noting
852 -- that parenthesization is required.
853
854 function P_If_Expression return Node_Id;
855 -- Scans out an if expression. Called with Token pointing to the
856 -- IF keyword, and returns pointing to the terminating right paren,
857 -- semicolon or comma, but does not consume this terminating token.
858
859 function P_Qualified_Expression (Subtype_Mark : Node_Id) return Node_Id;
860 -- This routine scans out a qualified expression when the caller has
861 -- already scanned out the name and apostrophe of the construct.
862
863 function P_Quantified_Expression return Node_Id;
864 -- This routine scans out a quantified expression when the caller has
865 -- already scanned out the keyword "for" of the construct.
866 end Ch4;
867
868 -------------
869 -- Par.Ch5 --
870 -------------
871
872 package Ch5 is
873 function P_Condition return Node_Id;
874 -- Scan out and return a condition. Note that an error is given if
875 -- the condition is followed by a right parenthesis.
876
877 function P_Condition (Cond : Node_Id) return Node_Id;
878 -- Similar to the above, but the caller has already scanned out the
879 -- conditional expression and passes it as an argument. This form of
880 -- the call does not check for a following right parenthesis.
881
882 function P_Iterator_Specification (Def_Id : Node_Id) return Node_Id;
883 -- Parse an iterator specification. The defining identifier has already
884 -- been scanned, as it is the common prefix between loop and iterator
885 -- specification.
886
887 function P_Loop_Parameter_Specification return Node_Id;
888 -- Used in loop constructs and quantified expressions.
889
890 function P_Sequence_Of_Statements
891 (SS_Flags : SS_Rec) return List_Id;
892 -- SS_Flags indicates the acceptable termination tokens; see body for
893 -- details. Handled is true if we are parsing a handled sequence of
894 -- statements.
895
896 procedure Parse_Decls_Begin_End (Parent : Node_Id);
897 -- Parses declarations and handled statement sequence, setting
898 -- fields of Parent node appropriately.
899 end Ch5;
900
901 -------------
902 -- Par.Ch6 --
903 -------------
904
905 package Ch6 is
906 function P_Designator return Node_Id;
907 function P_Defining_Program_Unit_Name return Node_Id;
908 function P_Formal_Part return List_Id;
909 function P_Parameter_Profile return List_Id;
910 function P_Return_Statement return Node_Id;
911 function P_Subprogram_Specification return Node_Id;
912
913 procedure P_Mode (Node : Node_Id);
914 -- Sets In_Present and/or Out_Present flags in Node scanning past IN,
915 -- OUT or IN OUT tokens in the source.
916
917 function P_Subprogram (Pf_Flags : Pf_Rec) return Node_Id;
918 -- Scans out any construct starting with either of the keywords
919 -- PROCEDURE or FUNCTION. The parameter indicates which possible
920 -- possible kinds of construct (body, spec, instantiation etc.)
921 -- are permissible in the current context.
922 end Ch6;
923
924 -------------
925 -- Par.Ch7 --
926 -------------
927
928 package Ch7 is
929 function P_Package (Pf_Flags : Pf_Rec) return Node_Id;
930 -- Scans out any construct starting with the keyword PACKAGE. The
931 -- parameter indicates which possible kinds of construct (body, spec,
932 -- instantiation etc.) are permissible in the current context.
933 end Ch7;
934
935 -------------
936 -- Par.Ch8 --
937 -------------
938
939 package Ch8 is
940 procedure P_Use_Clause (Item_List : List_Id);
941 end Ch8;
942
943 -------------
944 -- Par.Ch9 --
945 -------------
946
947 package Ch9 is
948 function P_Abort_Statement return Node_Id;
949 function P_Abortable_Part return Node_Id;
950 function P_Accept_Statement return Node_Id;
951 function P_Delay_Statement return Node_Id;
952 function P_Entry_Body return Node_Id;
953 function P_Protected return Node_Id;
954 function P_Requeue_Statement return Node_Id;
955 function P_Select_Statement return Node_Id;
956 function P_Task return Node_Id;
957 function P_Terminate_Alternative return Node_Id;
958 end Ch9;
959
960 --------------
961 -- Par.Ch10 --
962 --------------
963
964 package Ch10 is
965 function P_Compilation_Unit return Node_Id;
966 -- Note: this function scans a single compilation unit, and checks that
967 -- an end of file follows this unit, diagnosing any unexpected input as
968 -- an error, and then skipping it, so that Token is set to Tok_EOF on
969 -- return. An exception is in syntax-only mode, where multiple
970 -- compilation units are permitted. In this case, P_Compilation_Unit
971 -- does not check for end of file and there may be more compilation
972 -- units to scan. The caller can uniquely detect this situation by the
973 -- fact that Token is not set to Tok_EOF on return.
974 --
975 -- What about multiple unit/file capability that now exists???
976 --
977 -- The Ignore parameter is normally set False. It is set True in the
978 -- multiple unit per file mode if we are skipping past a unit that we
979 -- are not interested in.
980 end Ch10;
981
982 --------------
983 -- Par.Ch11 --
984 --------------
985
986 package Ch11 is
987 function P_Handled_Sequence_Of_Statements return Node_Id;
988 function P_Raise_Expression return Node_Id;
989 function P_Raise_Statement return Node_Id;
990
991 function Parse_Exception_Handlers return List_Id;
992 -- Parses the partial construct EXCEPTION followed by a list of
993 -- exception handlers which appears in a number of productions, and
994 -- returns the list of exception handlers.
995 end Ch11;
996
997 --------------
998 -- Par.Ch12 --
999 --------------
1000
1001 package Ch12 is
1002 function P_Generic return Node_Id;
1003 function P_Generic_Actual_Part_Opt return List_Id;
1004 end Ch12;
1005
1006 --------------
1007 -- Par.Ch13 --
1008 --------------
1009
1010 package Ch13 is
1011 function P_Representation_Clause return Node_Id;
1012
1013 function Aspect_Specifications_Present
1014 (Strict : Boolean := Ada_Version < Ada_2012) return Boolean;
1015 -- This function tests whether the next keyword is WITH followed by
1016 -- something that looks reasonably like an aspect specification. If so,
1017 -- True is returned. Otherwise False is returned. In either case control
1018 -- returns with the token pointer unchanged (i.e. pointing to the WITH
1019 -- token in the case where True is returned). This function takes care
1020 -- of generating appropriate messages if aspect specifications appear
1021 -- in versions of Ada prior to Ada 2012. The parameter strict can be
1022 -- set to True, to be rather strict about considering something to be
1023 -- an aspect specification. If Strict is False, then the circuitry is
1024 -- rather more generous in considering something ill-formed to be an
1025 -- attempt at an aspect specification. The default is more strict for
1026 -- Ada versions before Ada 2012 (where aspect specifications are not
1027 -- permitted). Note: this routine never checks the terminator token
1028 -- for aspects so it does not matter whether the aspect specifications
1029 -- are terminated by semicolon or some other character.
1030 --
1031 -- Note: This function also handles the case of WHEN used where WITH
1032 -- was intended, and in that case posts an error and returns True.
1033
1034 procedure P_Aspect_Specifications
1035 (Decl : Node_Id;
1036 Semicolon : Boolean);
1037 -- This procedure scans out a series of aspect specifications. If
1038 -- argument Semicolon is True, a terminating semicolon is also scanned;
1039 -- if False, the scan pointer is left pointing past the aspects and the
1040 -- caller must check for a proper terminator.
1041 --
1042 -- P_Aspect_Specifications is called with the current token pointing
1043 -- to either a WITH keyword starting an aspect specification, or an
1044 -- instance of what shpould be a terminator token. In the former case,
1045 -- the aspect specifications are scanned out including the terminator
1046 -- token if it is a semicolon, and the Has_Aspect_Specifications
1047 -- flag is set in the given declaration node. A list of aspects
1048 -- is built and stored for this declaration node using a call to
1049 -- Set_Aspect_Specifications. If no WITH keyword is present, then this
1050 -- call has no effect other than scanning out the terminator if it is a
1051 -- semicolon (with the exception that it detects WHEN used in place of
1052 -- WITH).
1053
1054 -- If Decl is Error or a node that does not allow aspect specifications,
1055 -- then any scanned aspect specifications are ignored and a message is
1056 -- output saying aspect specifications not permitted here. If Decl is
1057 -- Empty, then scanned aspect specifications are also ignored, but no
1058 -- error message is given (this is used when the caller has already
1059 -- taken care of the error message).
1060
1061 function Get_Aspect_Specifications (Semicolon : Boolean) return List_Id;
1062 -- Parse a list of aspects but do not attach them to a declaration node.
1063 -- Subsidiary to P_Aspect_Specifications procedure. Used when parsing
1064 -- a subprogram specification that may be a declaration or a body.
1065 -- Semicolon has the same meaning as for P_Aspect_Specifications above.
1066
1067 function P_Code_Statement (Subtype_Mark : Node_Id) return Node_Id;
1068 -- Function to parse a code statement. The caller has scanned out
1069 -- the name to be used as the subtype mark (but has not checked that
1070 -- it is suitable for use as a subtype mark, i.e. is either an
1071 -- identifier or a selected component). The current token is an
1072 -- apostrophe and the following token is either a left paren or
1073 -- RANGE (the latter being an error to be caught by P_Code_Statement.
1074 end Ch13;
1075
1076 -- Note: the parsing for annexe J features (i.e. obsolescent features)
1077 -- is found in the logical section where these features would be if
1078 -- they were not obsolescent. In particular:
1079
1080 -- Delta constraint is parsed by P_Delta_Constraint (3.5.9)
1081 -- At clause is parsed by P_At_Clause (13.1)
1082 -- Mod clause is parsed by P_Mod_Clause (13.5.1)
1083
1084 --------------
1085 -- Par.Endh --
1086 --------------
1087
1088 -- Routines for handling end lines, including scope recovery
1089
1090 package Endh is
1091 function Check_End
1092 (Decl : Node_Id := Empty;
1093 Is_Loc : Source_Ptr := No_Location) return Boolean;
1094 -- Called when an end sequence is required. In the absence of an error
1095 -- situation, Token contains Tok_End on entry, but in a missing end
1096 -- case, this may not be the case. Pop_End_Context is used to determine
1097 -- the appropriate action to be taken. The returned result is True if
1098 -- an End sequence was encountered and False if no End sequence was
1099 -- present. This occurs if the END keyword encountered was determined
1100 -- to be improper and deleted (i.e. Pop_End_Context set End_Action to
1101 -- Skip_And_Reject). Note that the END sequence includes a semicolon,
1102 -- except in the case of END RECORD, where a semicolon follows the END
1103 -- RECORD, but is not part of the record type definition itself.
1104 --
1105 -- If Decl is non-empty, then aspect specifications are permitted
1106 -- following the end, and Decl is the declaration node with which
1107 -- these aspect specifications are to be associated. If Decl is empty,
1108 -- then aspect specifications are not permitted and will generate an
1109 -- error message.
1110 --
1111 -- Is_Loc is set to other than the default only for the case of a
1112 -- package declaration. It points to the IS keyword of the declaration,
1113 -- and is used to specialize the error messages for misplaced aspect
1114 -- specifications in this case. Note that Decl is always Empty if Is_Loc
1115 -- is set.
1116
1117 procedure End_Skip;
1118 -- Skip past an end sequence. On entry Token contains Tok_End, and we
1119 -- we know that the end sequence is syntactically incorrect, and that
1120 -- an appropriate error message has already been posted. The mission
1121 -- is simply to position the scan pointer to be the best guess of the
1122 -- position after the end sequence. We do not issue any additional
1123 -- error messages while carrying this out.
1124
1125 procedure End_Statements
1126 (Parent : Node_Id := Empty;
1127 Decl : Node_Id := Empty;
1128 Is_Sloc : Source_Ptr := No_Location);
1129 -- Called when an end is required or expected to terminate a sequence
1130 -- of statements. The caller has already made an appropriate entry in
1131 -- the Scope.Table to describe the expected form of the end. This can
1132 -- only be used in cases where the only appropriate terminator is end.
1133 -- If Parent is non-empty, then if a correct END line is encountered,
1134 -- the End_Label field of Parent is set appropriately.
1135 --
1136 -- If Decl is non-null, then it is a declaration node, and aspect
1137 -- specifications are permitted after the end statement. These aspect
1138 -- specifications, if present, are stored in this declaration node.
1139 -- If Decl is null, then aspect specifications are not permitted after
1140 -- the end statement.
1141 --
1142 -- In the case where Decl is null, Is_Sloc determines the handling. If
1143 -- it is set to No_Location, then aspect specifications are ignored and
1144 -- an error message is given. Is_Sloc is used in the package declaration
1145 -- case to point to the IS, and is used to specialize the error emssages
1146 -- issued in this case.
1147 end Endh;
1148
1149 --------------
1150 -- Par.Sync --
1151 --------------
1152
1153 -- These procedures are used to resynchronize after errors. Following an
1154 -- error which is not immediately locally recoverable, the exception
1155 -- Error_Resync is raised. The handler for Error_Resync typically calls
1156 -- one of these recovery procedures to resynchronize the source position
1157 -- to a point from which parsing can be restarted.
1158
1159 -- Note: these procedures output an information message that tokens are
1160 -- being skipped, but this message is output only if the option for
1161 -- Multiple_Errors_Per_Line is set in Options.
1162
1163 package Sync is
1164 procedure Resync_Choice;
1165 -- Used if an error occurs scanning a choice. The scan pointer is
1166 -- advanced to the next vertical bar, arrow, or semicolon, whichever
1167 -- comes first. We also quit if we encounter an end of file.
1168
1169 procedure Resync_Cunit;
1170 -- Synchronize to next token which could be the start of a compilation
1171 -- unit, or to the end of file token.
1172
1173 procedure Resync_Expression;
1174 -- Used if an error is detected during the parsing of an expression.
1175 -- It skips past tokens until either a token which cannot be part of
1176 -- an expression is encountered (an expression terminator), or if a
1177 -- comma or right parenthesis or vertical bar is encountered at the
1178 -- current parenthesis level (a parenthesis level counter is maintained
1179 -- to carry out this test).
1180
1181 procedure Resync_Past_Malformed_Aspect;
1182 -- Used when parsing aspect specifications to skip a malformed aspect.
1183 -- The scan pointer is positioned next to a comma, a semicolon or "is"
1184 -- when the aspect applies to a body.
1185
1186 procedure Resync_Past_Semicolon;
1187 -- Used if an error occurs while scanning a sequence of declarations.
1188 -- The scan pointer is positioned past the next semicolon and the scan
1189 -- resumes. The scan is also resumed on encountering a token which
1190 -- starts a declaration (but we make sure to skip at least one token
1191 -- in this case, to avoid getting stuck in a loop).
1192
1193 procedure Resync_Past_Semicolon_Or_To_Loop_Or_Then;
1194 -- Used if an error occurs while scanning a sequence of statements. The
1195 -- scan pointer is positioned past the next semicolon, or to the next
1196 -- occurrence of either then or loop, and the scan resumes.
1197
1198 procedure Resync_Semicolon_List;
1199 -- Used if an error occurs while scanning a parenthesized list of items
1200 -- separated by semicolons. The scan pointer is advanced to the next
1201 -- semicolon or right parenthesis at the outer parenthesis level, or
1202 -- to the next is or RETURN keyword occurrence, whichever comes first.
1203
1204 procedure Resync_To_Semicolon;
1205 -- Similar to Resync_Past_Semicolon, except that the scan pointer is
1206 -- left pointing to the semicolon rather than past it.
1207
1208 procedure Resync_To_When;
1209 -- Used when an error occurs scanning an entry index specification. The
1210 -- scan pointer is positioned to the next WHEN (or to IS or semicolon if
1211 -- either of these appear before WHEN, indicating another error has
1212 -- occurred).
1213 end Sync;
1214
1215 --------------
1216 -- Par.Tchk --
1217 --------------
1218
1219 -- Routines to check for expected tokens
1220
1221 package Tchk is
1222
1223 -- Procedures with names of the form T_xxx, where Tok_xxx is a token
1224 -- name, check that the current token matches the required token, and
1225 -- if so, scan past it. If not, an error is issued indicating that
1226 -- the required token is not present (xxx expected). In most cases, the
1227 -- scan pointer is not moved in the not-found case, but there are some
1228 -- exceptions to this, see for example T_Id, where the scan pointer is
1229 -- moved across a literal appearing where an identifier is expected.
1230
1231 procedure T_Abort;
1232 procedure T_Arrow;
1233 procedure T_At;
1234 procedure T_Body;
1235 procedure T_Box;
1236 procedure T_Colon;
1237 procedure T_Colon_Equal;
1238 procedure T_Comma;
1239 procedure T_Dot_Dot;
1240 procedure T_For;
1241 procedure T_Greater_Greater;
1242 procedure T_Identifier;
1243 procedure T_In;
1244 procedure T_Is;
1245 procedure T_Left_Paren;
1246 procedure T_Loop;
1247 procedure T_Mod;
1248 procedure T_New;
1249 procedure T_Of;
1250 procedure T_Or;
1251 procedure T_Private;
1252 procedure T_Range;
1253 procedure T_Record;
1254 procedure T_Right_Bracket;
1255 procedure T_Right_Curly_Bracket;
1256 procedure T_Right_Paren;
1257 procedure T_Semicolon;
1258 procedure T_Then;
1259 procedure T_Type;
1260 procedure T_Use;
1261 procedure T_When;
1262 procedure T_With;
1263
1264 -- Procedures having names of the form TF_xxx, where Tok_xxx is a token
1265 -- name check that the current token matches the required token, and
1266 -- if so, scan past it. If not, an error message is issued indicating
1267 -- that the required token is not present (xxx expected).
1268
1269 -- If the missing token is at the end of the line, then control returns
1270 -- immediately after posting the message. If there are remaining tokens
1271 -- on the current line, a search is conducted to see if the token
1272 -- appears later on the current line, as follows:
1273
1274 -- A call to Scan_Save is issued and a forward search for the token
1275 -- is carried out. If the token is found on the current line before a
1276 -- semicolon, then it is scanned out and the scan continues from that
1277 -- point. If not the scan is restored to the point where it was missing.
1278
1279 procedure TF_Arrow;
1280 procedure TF_Is;
1281 procedure TF_Loop;
1282 procedure TF_Return;
1283 procedure TF_Semicolon;
1284 procedure TF_Then;
1285 procedure TF_Use;
1286
1287 -- Procedures with names of the form U_xxx, where Tok_xxx is a token
1288 -- name, are just like the corresponding T_xxx procedures except that
1289 -- an error message, if given, is unconditional.
1290
1291 procedure U_Left_Paren;
1292 procedure U_Right_Paren;
1293 end Tchk;
1294
1295 --------------
1296 -- Par.Util --
1297 --------------
1298
1299 package Util is
1300 function Bad_Spelling_Of (T : Token_Type) return Boolean;
1301 -- This function is called in an error situation. It checks if the
1302 -- current token is an identifier whose name is a plausible bad
1303 -- spelling of the given keyword token, and if so, issues an error
1304 -- message, sets Token from T, and returns True. Otherwise Token is
1305 -- unchanged, and False is returned.
1306
1307 procedure Check_Bad_Layout;
1308 -- Check for bad indentation in RM checking mode. Used for statements
1309 -- and declarations. Checks if current token is at start of line and
1310 -- is exdented from the current expected end column, and if so an
1311 -- error message is generated.
1312
1313 procedure Check_Misspelling_Of (T : Token_Type);
1314 pragma Inline (Check_Misspelling_Of);
1315 -- This is similar to the function above, except that it does not
1316 -- return a result. It is typically used in a situation where any
1317 -- identifier is an error, and it makes sense to simply convert it
1318 -- to the given token if it is a plausible misspelling of it.
1319
1320 procedure Check_95_Keyword (Token_95, Next : Token_Type);
1321 -- This routine checks if the token after the current one matches the
1322 -- Next argument. If so, the scan is backed up to the current token
1323 -- and Token_Type is changed to Token_95 after issuing an appropriate
1324 -- error message ("(Ada 83) keyword xx cannot be used"). If not,
1325 -- the scan is backed up with Token_Type unchanged. This routine
1326 -- is used to deal with an attempt to use a 95 keyword in Ada 83
1327 -- mode. The caller has typically checked that the current token,
1328 -- an identifier, matches one of the 95 keywords.
1329
1330 procedure Check_Future_Keyword;
1331 -- Emit a warning if the current token is a valid identifier in the
1332 -- language version in use, but is a reserved word in a later language
1333 -- version (unless the language version in use is Ada 83).
1334
1335 procedure Check_Simple_Expression (E : Node_Id);
1336 -- Given an expression E, that has just been scanned, so that Expr_Form
1337 -- is still set, outputs an error if E is a non-simple expression. E is
1338 -- not modified by this call.
1339
1340 procedure Check_Simple_Expression_In_Ada_83 (E : Node_Id);
1341 -- Like Check_Simple_Expression, except that the error message is only
1342 -- given when operating in Ada 83 mode, and includes "in Ada 83".
1343
1344 function Check_Subtype_Mark (Mark : Node_Id) return Node_Id;
1345 -- Called to check that a node representing a name (or call) is
1346 -- suitable for a subtype mark, i.e, that it is an identifier or
1347 -- a selected component. If so, or if it is already Error, then
1348 -- it is returned unchanged. Otherwise an error message is issued
1349 -- and Error is returned.
1350
1351 function Comma_Present return Boolean;
1352 -- Used in comma delimited lists to determine if a comma is present, or
1353 -- can reasonably be assumed to have been present (an error message is
1354 -- generated in the latter case). If True is returned, the scan has been
1355 -- positioned past the comma. If False is returned, the scan position
1356 -- is unchanged. Note that all comma-delimited lists are terminated by
1357 -- a right paren, so the only legitimate tokens when Comma_Present is
1358 -- called are right paren and comma. If some other token is found, then
1359 -- Comma_Present has the job of deciding whether it is better to pretend
1360 -- a comma was present, post a message for a missing comma and return
1361 -- True, or return False and let the caller diagnose the missing right
1362 -- parenthesis.
1363
1364 procedure Discard_Junk_Node (N : Node_Id);
1365 procedure Discard_Junk_List (L : List_Id);
1366 pragma Inline (Discard_Junk_Node);
1367 pragma Inline (Discard_Junk_List);
1368 -- These procedures do nothing at all, their effect is simply to discard
1369 -- the argument. A typical use is to skip by some junk that is not
1370 -- expected in the current context.
1371
1372 procedure Ignore (T : Token_Type);
1373 -- If current token matches T, then give an error message and skip
1374 -- past it, otherwise the call has no effect at all. T may be any
1375 -- reserved word token, or comma, left or right paren, or semicolon.
1376
1377 function Is_Reserved_Identifier (C : Id_Check := None) return Boolean;
1378 -- Test if current token is a reserved identifier. This test is based
1379 -- on the token being a keyword and being spelled in typical identifier
1380 -- style (i.e. starting with an upper case letter). The parameter C
1381 -- determines the special treatment if a reserved word is encountered
1382 -- that has the normal casing of a reserved word.
1383
1384 procedure Merge_Identifier (Prev : Node_Id; Nxt : Token_Type);
1385 -- Called when the previous token is an identifier (whose Token_Node
1386 -- value is given by Prev) to check if current token is an identifier
1387 -- that can be merged with the previous one adding an underscore. The
1388 -- merge is only attempted if the following token matches Nxt. If all
1389 -- conditions are met, an error message is issued, and the merge is
1390 -- carried out, modifying the Chars field of Prev.
1391
1392 function Missing_Semicolon_On_When return Boolean;
1393 -- This function deals with the following specialized situations
1394 --
1395 -- when 'x' =>
1396 -- exit/return [identifier]
1397 -- when 'y' =>
1398 --
1399 -- This looks like a messed up EXIT WHEN or RETURN WHEN, when in fact
1400 -- the problem is a missing semicolon. It is called with Token pointing
1401 -- to the WHEN token, and returns True if a semicolon is missing before
1402 -- the WHEN as in the above example.
1403
1404 function Next_Token_Is (Tok : Token_Type) return Boolean;
1405 -- Looks at token after current one and returns True if the token type
1406 -- matches Tok. The scan is unconditionally restored on return.
1407
1408 procedure No_Constraint;
1409 -- Called in a place where no constraint is allowed, but one might
1410 -- appear due to a common error (e.g. after the type mark in a procedure
1411 -- parameter. If a constraint is present, an error message is posted,
1412 -- and the constraint is scanned and discarded.
1413
1414 procedure Push_Scope_Stack;
1415 pragma Inline (Push_Scope_Stack);
1416 -- Push a new entry onto the scope stack. Scope.Last (the stack pointer)
1417 -- is incremented. The Junk field is preinitialized to False. The caller
1418 -- is expected to fill in all remaining entries of the new top stack
1419 -- entry at Scopes (Scope.Last).
1420
1421 procedure Pop_Scope_Stack;
1422 -- Pop an entry off the top of the scope stack. Scope_Last (the scope
1423 -- table stack pointer) is decremented by one. It is a fatal error to
1424 -- try to pop off the dummy entry at the bottom of the stack (i.e.
1425 -- Scope.Last must be non-zero at the time of call).
1426
1427 function Separate_Present return Boolean;
1428 -- Determines if the current token is either Tok_Separate, or an
1429 -- identifier that is a possible misspelling of "separate" followed
1430 -- by a semicolon. True is returned if so, otherwise False.
1431
1432 procedure Signal_Bad_Attribute;
1433 -- The current token is an identifier that is supposed to be an
1434 -- attribute identifier but is not. This routine posts appropriate
1435 -- error messages, including a check for a near misspelling.
1436
1437 function Token_Is_At_Start_Of_Line return Boolean;
1438 pragma Inline (Token_Is_At_Start_Of_Line);
1439 -- Determines if the current token is the first token on the line
1440
1441 function Token_Is_At_End_Of_Line return Boolean;
1442 -- Determines if the current token is the last token on the line
1443
1444 procedure Warn_If_Standard_Redefinition (N : Node_Id);
1445 -- Issues a warning if Warn_On_Standard_Redefinition is set True, and
1446 -- the Node N (which is a Defining_Identifier node with the Chars field
1447 -- set) is a renaming of an entity in package Standard.
1448
1449 end Util;
1450
1451 --------------
1452 -- Par.Prag --
1453 --------------
1454
1455 -- The processing for pragmas is split off from chapter 2
1456
1457 function Prag (Pragma_Node : Node_Id; Semi : Source_Ptr) return Node_Id;
1458 -- This function is passed a tree for a pragma that has been scanned out.
1459 -- The pragma is syntactically well formed according to the general syntax
1460 -- for pragmas and the pragma identifier is for one of the recognized
1461 -- pragmas. It performs specific syntactic checks for specific pragmas.
1462 -- The result is the input node if it is OK, or Error otherwise. The
1463 -- reason that this is separated out is to facilitate the addition
1464 -- of implementation defined pragmas. The second parameter records the
1465 -- location of the semicolon following the pragma (this is needed for
1466 -- correct processing of the List and Page pragmas). The returned value
1467 -- is a copy of Pragma_Node, or Error if an error is found. Note that
1468 -- at the point where Prag is called, the right paren ending the pragma
1469 -- has been scanned out, and except in the case of pragma Style_Checks,
1470 -- so has the following semicolon. For Style_Checks, the caller delays
1471 -- the scanning of the semicolon so that it will be scanned using the
1472 -- settings from the Style_Checks pragma preceding it.
1473
1474 --------------
1475 -- Par.Labl --
1476 --------------
1477
1478 procedure Labl;
1479 -- This procedure creates implicit label declarations for all labels that
1480 -- are declared in the current unit. Note that this could conceptually be
1481 -- done at the point where the labels are declared, but it is tricky to do
1482 -- it then, since the tree is not hooked up at the point where the label is
1483 -- declared (e.g. a sequence of statements is not yet attached to its
1484 -- containing scope at the point a label in the sequence is found).
1485
1486 --------------
1487 -- Par.Load --
1488 --------------
1489
1490 procedure Load;
1491 -- This procedure loads all subsidiary units that are required by this
1492 -- unit, including with'ed units, specs for bodies, and parents for child
1493 -- units. It does not load bodies for inlined procedures and generics,
1494 -- since we don't know till semantic analysis is complete what is needed.
1495
1496 -----------
1497 -- Stubs --
1498 -----------
1499
1500 -- The package bodies can see all routines defined in all other subpackages
1501
1502 use Ch2;
1503 use Ch3;
1504 use Ch4;
1505 use Ch5;
1506 use Ch6;
1507 use Ch7;
1508 use Ch8;
1509 use Ch9;
1510 use Ch10;
1511 use Ch11;
1512 use Ch12;
1513 use Ch13;
1514
1515 use Endh;
1516 use Tchk;
1517 use Sync;
1518 use Util;
1519
1520 package body Ch2 is separate;
1521 package body Ch3 is separate;
1522 package body Ch4 is separate;
1523 package body Ch5 is separate;
1524 package body Ch6 is separate;
1525 package body Ch7 is separate;
1526 package body Ch8 is separate;
1527 package body Ch9 is separate;
1528 package body Ch10 is separate;
1529 package body Ch11 is separate;
1530 package body Ch12 is separate;
1531 package body Ch13 is separate;
1532
1533 package body Endh is separate;
1534 package body Tchk is separate;
1535 package body Sync is separate;
1536 package body Util is separate;
1537
1538 function Prag (Pragma_Node : Node_Id; Semi : Source_Ptr) return Node_Id
1539 is separate;
1540
1541 procedure Labl is separate;
1542 procedure Load is separate;
1543
1544 Result : List_Id := Empty_List;
1545
1546 -- Start of processing for Par
1547
1548 begin
1549 Compiler_State := Parsing;
1550
1551 -- Deal with configuration pragmas case first
1552
1553 if Configuration_Pragmas then
1554 declare
1555 Pragmas : constant List_Id := Empty_List;
1556 P_Node : Node_Id;
1557
1558 begin
1559 loop
1560 if Token = Tok_EOF then
1561 Result := Pragmas;
1562 exit;
1563
1564 elsif Token /= Tok_Pragma then
1565 Error_Msg_SC ("only pragmas allowed in configuration file");
1566 Result := Error_List;
1567 exit;
1568
1569 else
1570 P_Node := P_Pragma;
1571
1572 if Nkind (P_Node) = N_Pragma then
1573
1574 -- Give error if bad pragma
1575
1576 if not Is_Configuration_Pragma_Name
1577 (Pragma_Name_Unmapped (P_Node))
1578 and then
1579 Pragma_Name_Unmapped (P_Node) /= Name_Source_Reference
1580 then
1581 if Is_Pragma_Name (Pragma_Name_Unmapped (P_Node)) then
1582 Error_Msg_N
1583 ("only configuration pragmas allowed " &
1584 "in configuration file", P_Node);
1585 else
1586 Error_Msg_N
1587 ("unrecognized pragma in configuration file",
1588 P_Node);
1589 end if;
1590
1591 -- Pragma is OK config pragma, so collect it
1592
1593 else
1594 Append (P_Node, Pragmas);
1595 end if;
1596 end if;
1597 end if;
1598 end loop;
1599 end;
1600
1601 if Config_Files_Store_Basename then
1602 Complete_Source_File_Entry;
1603 end if;
1604
1605 -- Normal case of compilation unit
1606
1607 else
1608 Save_Config_Attrs := Save_Config_Switches;
1609
1610 -- Store the state of Style_Checks pragamas
1611
1612 Save_Style_Check := Style_Check;
1613 Save_Style_Check_Options (Save_Style_Checks);
1614
1615 -- The following loop runs more than once in syntax check mode
1616 -- where we allow multiple compilation units in the same file
1617 -- and in Multiple_Unit_Per_file mode where we skip units till
1618 -- we get to the unit we want.
1619
1620 for Ucount in Pos loop
1621 Set_Config_Switches
1622 (Is_Internal_Unit (Current_Source_Unit),
1623 Main_Unit => Current_Source_Unit = Main_Unit);
1624
1625 -- Initialize scope table and other parser control variables
1626
1627 Compiler_State := Parsing;
1628 Scope.Init;
1629 Scope.Increment_Last;
1630 Scopes (0).Etyp := E_Dummy;
1631 SIS_Entry_Active := False;
1632 Last_Resync_Point := No_Location;
1633
1634 Goto_List := New_Elmt_List;
1635 Label_List := New_Elmt_List;
1636
1637 -- If in multiple unit per file mode, skip past ignored unit
1638
1639 if Ucount < Multiple_Unit_Index then
1640
1641 -- We skip in syntax check only mode, since we don't want to do
1642 -- anything more than skip past the unit and ignore it. This means
1643 -- we skip processing like setting up a unit table entry.
1644
1645 declare
1646 Save_Operating_Mode : constant Operating_Mode_Type :=
1647 Operating_Mode;
1648
1649 Save_Style_Check : constant Boolean := Style_Check;
1650
1651 begin
1652 Operating_Mode := Check_Syntax;
1653 Style_Check := False;
1654 Discard_Node (P_Compilation_Unit);
1655 Operating_Mode := Save_Operating_Mode;
1656 Style_Check := Save_Style_Check;
1657
1658 -- If we are at an end of file, and not yet at the right unit,
1659 -- then we have a fatal error. The unit is missing.
1660
1661 if Token = Tok_EOF then
1662 Error_Msg_SC ("file has too few compilation units");
1663 raise Unrecoverable_Error;
1664 end if;
1665 end;
1666
1667 -- Here if we are not skipping a file in multiple unit per file mode.
1668 -- Parse the unit that we are interested in. Note that in check
1669 -- syntax mode we are interested in all units in the file.
1670
1671 else
1672
1673 declare
1674 Comp_Unit_Node : constant Node_Id := P_Compilation_Unit;
1675
1676 begin
1677 -- If parsing was successful and we are not in check syntax
1678 -- mode, check that language-defined units are compiled in GNAT
1679 -- mode. For this purpose we do NOT consider renamings in annex
1680 -- J as predefined. That allows users to compile their own
1681 -- versions of these files. Another exception is System.RPC
1682 -- and its children. This allows a user to supply their own
1683 -- communication layer.
1684 -- Similarly, we do not generate an error in CodePeer mode,
1685 -- to allow users to analyze third-party compiler packages.
1686
1687 if Comp_Unit_Node /= Error
1688 and then Operating_Mode = Generate_Code
1689 and then Current_Source_Unit = Main_Unit
1690 and then not GNAT_Mode
1691 and then not CodePeer_Mode
1692 then
1693 declare
1694 Uname : constant String :=
1695 Get_Name_String
1696 (Unit_Name (Current_Source_Unit));
1697 Name : String renames
1698 Uname (Uname'First .. Uname'Last - 2);
1699 -- Because Unit_Name includes "%s"/"%b", we need to strip
1700 -- the last two characters to get the real unit name.
1701
1702 begin
1703 if Name = "ada" or else
1704 Name = "interfaces" or else
1705 Name = "system"
1706 then
1707 Error_Msg
1708 ("language-defined units cannot be recompiled",
1709 Sloc (Unit (Comp_Unit_Node)));
1710
1711 elsif Name'Length > 4
1712 and then
1713 Name (Name'First .. Name'First + 3) = "ada."
1714 then
1715 Error_Msg
1716 ("user-defined descendants of package Ada " &
1717 "are not allowed",
1718 Sloc (Unit (Comp_Unit_Node)));
1719
1720 elsif Name'Length > 11
1721 and then
1722 Name (Name'First .. Name'First + 10) = "interfaces."
1723 then
1724 Error_Msg
1725 ("user-defined descendants of package Interfaces " &
1726 "are not allowed",
1727 Sloc (Unit (Comp_Unit_Node)));
1728
1729 elsif Name'Length > 7
1730 and then Name (Name'First .. Name'First + 6) = "system."
1731 and then Name /= "system.rpc"
1732 and then
1733 (Name'Length < 11
1734 or else Name (Name'First .. Name'First + 10) /=
1735 "system.rpc.")
1736 then
1737 Error_Msg
1738 ("user-defined descendants of package System " &
1739 "are not allowed",
1740 Sloc (Unit (Comp_Unit_Node)));
1741 end if;
1742 end;
1743 end if;
1744 end;
1745
1746 -- All done if at end of file
1747
1748 exit when Token = Tok_EOF;
1749
1750 -- If we are not at an end of file, it means we are in syntax
1751 -- check only mode, and we keep the loop going to parse all
1752 -- remaining units in the file.
1753
1754 end if;
1755
1756 Restore_Config_Switches (Save_Config_Attrs);
1757 end loop;
1758
1759 -- Restore the state of Style_Checks after parsing the unit to
1760 -- avoid parsed pragmas affecting other units.
1761
1762 Reset_Style_Check_Options;
1763 Set_Style_Check_Options (Save_Style_Checks);
1764 Style_Check := Save_Style_Check;
1765
1766 -- Now that we have completely parsed the source file, we can complete
1767 -- the source file table entry.
1768
1769 Complete_Source_File_Entry;
1770
1771 -- An internal error check, the scope stack should now be empty
1772
1773 pragma Assert (Scope.Last = 0);
1774
1775 -- Here we make the SCO table entries for the main unit
1776
1777 if Generate_SCO then
1778 SCO_Record_Raw (Main_Unit);
1779 end if;
1780
1781 -- Remaining steps are to create implicit label declarations and to load
1782 -- required subsidiary sources. These steps are required only if we are
1783 -- doing semantic checking.
1784
1785 if Operating_Mode /= Check_Syntax or else Debug_Flag_F then
1786 Par.Labl;
1787 Par.Load;
1788 end if;
1789
1790 -- Restore settings of switches saved on entry
1791
1792 Restore_Config_Switches (Save_Config_Attrs);
1793 Set_Comes_From_Source_Default (False);
1794 end if;
1795
1796 Compiler_State := Analyzing;
1797 Current_Source_File := No_Source_File;
1798 return Result;
1799 end Par;