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