OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-stable/] [gcc-4.5.1/] [gcc/] [ada/] [par.adb] - Blame information for rev 281

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.