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