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