1 /* st.c -- Implementation File (module.c template V1.0)
2 Copyright (C) 1995 Free Software Foundation, Inc.
3 Contributed by James Craig Burley.
5 This file is part of GNU Fortran.
7 GNU Fortran is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Fortran is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Fortran; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
26 The high-level input level to statement handling for the rest of the
27 FFE. ffest_first is the first state for the lexer to invoke to start
28 a statement. A statement normally starts with a NUMBER token (to indicate
29 a label def) followed by a NAME token (to indicate what kind of statement
30 it is), though of course the NUMBER token may be omitted. ffest_first
31 gathers the first NAME token and returns a state of ffest_second_,
32 where the trailing underscore means "internal to ffest" and thus outside
33 users should not depend on this. ffest_second_ then looks at the second
34 token in conjunction with the first, decides what possible statements are
35 meant, and tries each possible statement in turn, from most likely to
36 least likely. A successful attempt currently is recorded, and further
37 successful attempts by other possibilities raise an assertion error in
38 ffest_confirmed (this is to detect ambiguities). A failure in an
39 attempt is signaled by calling ffest_ffebad_start; this results in the
40 next token sent by ffest_save_ (the intermediary when more than one
41 possible statement exists) being EOS to shut down processing and the next
44 When all possibilities have been tried, the successful one is retried with
45 inhibition turned off (FALSE) as reported by ffest_is_inhibited(). If
46 there is no successful one, the first one is retried so the user gets to
47 see the error messages.
49 In the future, after syntactic bugs have been reasonably shaken out and
50 ambiguities thus detected, the first successful possibility will be
51 enabled (inhibited goes FALSE) as soon as it confirms success by calling
52 ffest_confirmed, thus retrying the possibility will not be necessary.
54 The only complication in all this is that expression handling is
55 happening while possibilities are inhibited. It is up to the expression
56 handler, conceptually, to not make any changes to its knowledge base for
57 variable names and so on when inhibited that cannot be undone if
58 the current possibility fails (shuts down via ffest_ffebad_start). In
59 fact, this business is handled not be ffeexpr, but by lower levels.
61 ffesta functions serve only to provide information used in syntactic
62 processing of possible statements, and thus may not make changes to the
63 knowledge base for variables and such.
65 ffestb functions perform the syntactic analysis for possible statements,
66 and thus again may not make changes to the knowledge base except under the
67 auspices of ffeexpr and its subordinates, changes which can be undone when
70 ffestc functions perform the semantic analysis for the chosen statement,
71 and thus may change the knowledge base as necessary since they are invoked
72 by ffestb functions only after a given statement is confirmed and
73 enabled. Note, however, that a few ffestc functions (identified by
74 their statement names rather than grammar numbers) indicate valid forms
75 that are, outside of any context, ambiguous, such as ELSE WHERE and
76 PRIVATE; these functions should make a quick decision as to what is
77 intended and dispatch to the appropriate specific ffestc function.
79 ffestd functions actually implement statements. When called, the
80 statement is considered valid and is either an executable statement or
81 a nonexecutable statement with direct-output results. For example, CALL,
82 GOTO, and assignment statements pass through ffestd because they are
83 executable; DATA statements pass through because they map directly to the
84 output file (or at least might so map); ENTRY statements also pass through
85 because they essentially affect code generation in an immediate way;
86 whereas INTEGER, SAVE, and SUBROUTINE statements do not go through
87 ffestd functions because they merely update the knowledge base.
111 /* Externals defined here. */
114 /* Simple definitions and enumerations. */
117 /* Internal typedefs. */
120 /* Private include files. */
123 /* Internal structure definitions. */
126 /* Static objects accessed by functions in this module. */
129 /* Static functions (internal). */
132 /* Internal macros. */
135 /* ffest_confirmed -- Confirm current possibility as only one
139 Sets the confirmation flag. During debugging for ambiguous constructs,
140 asserts that the confirmation flag for a previous possibility has not
149 /* ffest_eof -- End of (non-INCLUDEd) source file
153 Call after piping tokens through ffest_first, where the most recent
154 token sent through must be EOS.
157 Put new EOF token in ffesta_tokens[0], not NULL, because too much
158 code expects something there for error reporting and the like. Also,
159 do basically the same things ffest_second and ffesta_zero do for
160 processing a statement (make and destroy pools, et cetera). */
168 /* ffest_ffebad_here_current_stmt -- ffebad_here with ptr to current stmt
170 ffest_ffebad_here_current_stmt(0);
172 Outsiders can call this fn if they have no more convenient place to
173 point to (via a token or pair of ffewhere objects) and they know a
174 current, useful statement is being evaluted by ffest (i.e. they are
175 being called from ffestb, ffestc, ffestd, ... functions). */
178 ffest_ffebad_here_current_stmt (ffebadIndex i
)
180 ffesta_ffebad_here_current_stmt (i
);
183 /* ffest_ffebad_here_doiter -- Calls ffebad_here with ptr to DO iter var
186 // call ffebad_start first, of course.
187 ffest_ffebad_here_doiter(0,s);
188 // call ffebad_finish afterwards, naturally.
190 Searches the stack of blocks backwards for a DO loop that has s
191 as its iteration variable, then calls ffebad_here with pointers to
192 that particular reference to the variable. Crashes if the DO loop
196 ffest_ffebad_here_doiter (ffebadIndex i
, ffesymbol s
)
198 ffestc_ffebad_here_doiter (i
, s
);
201 /* ffest_ffebad_start -- Start a possibly inhibited error report
203 if (ffest_ffebad_start(FFEBAD_SOME_ERROR))
205 ffebad_here, ffebad_string ...;
209 Call if the error might indicate that ffest is evaluating the wrong
210 statement form, instead of calling ffebad_start directly. If ffest
211 is choosing between forms, it will return FALSE, send an EOS/SEMICOLON
212 token through as the next token (if the current one isn't already one
213 of those), and try another possible form. Otherwise, ffebad_start is
214 called with the argument and TRUE returned. */
217 ffest_ffebad_start (ffebad errnum
)
219 return ffesta_ffebad_start (errnum
);
222 /* ffest_first -- Parse the first token in a statement
224 return ffest_first; // to lexer. */
227 ffest_first (ffelexToken t
)
229 return ffesta_first (t
);
232 /* ffest_init_0 -- Initialize for entire image invocation
236 Call just once per invocation of the compiler (not once per invocation
239 Gets memory for the list of possibles once and for all, since this
240 list never gets larger than a certain size (FFEST_maxPOSSIBLES_)
241 and is not particularly large. Initializes the array of pointers to
242 this list. Initializes the executable and nonexecutable lists. */
261 /* ffest_init_1 -- Initialize for entire image invocation
265 Call just once per invocation of the compiler (not once per invocation
268 Gets memory for the list of possibles once and for all, since this
269 list never gets larger than a certain size (FFEST_maxPOSSIBLES_)
270 and is not particularly large. Initializes the array of pointers to
271 this list. Initializes the executable and nonexecutable lists. */
290 /* ffest_init_2 -- Initialize for entire image invocation
294 Call just once per invocation of the compiler (not once per invocation
297 Gets memory for the list of possibles once and for all, since this
298 list never gets larger than a certain size (FFEST_maxPOSSIBLES_)
299 and is not particularly large. Initializes the array of pointers to
300 this list. Initializes the executable and nonexecutable lists. */
319 /* ffest_init_3 -- Initialize for any program unit
339 ffestw_display_state ();
342 /* ffest_init_4 -- Initialize for statement functions
363 /* Test whether ENTRY statement is valid.
365 Returns TRUE if current program unit is known to be FUNCTION or SUBROUTINE.
366 Else returns FALSE. */
369 ffest_is_entry_valid ()
371 return ffesta_is_entry_valid
;
374 /* ffest_is_inhibited -- Test whether the current possibility is inhibited
376 if (!ffest_is_inhibited())
377 // implement the statement.
379 Just make sure the current possibility has been confirmed. If anyone
380 really needs to test whether the current possibility is inhibited prior
381 to confirming it, that indicates a need to begin statement processing
382 before it is certain that the given possibility is indeed the statement
383 to be processed. As of this writing, there does not appear to be such
384 a need. If there is, then when confirming a statement would normally
385 immediately disable the inhibition (whereas currently we leave the
386 confirmed statement disabled until we've tried the other possibilities,
387 to check for ambiguities), we must check to see if the possibility has
388 already tested for inhibition prior to confirmation and, if so, maintain
389 inhibition until the end of the statement (which may be forced right
390 away) and then rerun the entire statement from the beginning. Otherwise,
391 initial calls to ffestb functions won't have been made, but subsequent
392 calls (after confirmation) will, which is wrong. Of course, this all
393 applies only to those statements implemented via multiple calls to
394 ffestb, although if a statement requiring only a single ffestb call
395 tested for inhibition prior to confirmation, it would likely mean that
396 the ffestb call would be completely dropped without this mechanism. */
399 ffest_is_inhibited ()
401 return ffesta_is_inhibited ();
404 /* ffest_seen_first_exec -- Test whether first executable stmt has been seen
406 if (ffest_seen_first_exec())
407 // No more spec stmts can be seen.
409 In a case where, say, the first statement is PARAMETER(A)=B, FALSE
410 will be returned while the PARAMETER statement is being run, and TRUE
411 will be returned if it doesn't confirm and the assignment statement
415 ffest_seen_first_exec ()
417 return ffesta_seen_first_exec
;
420 /* Shut down current parsing possibility, but without bothering the
421 user with a diagnostic if we're not inhibited. */
429 /* ffest_sym_end_transition -- Update symbol info just before end of unit
432 ffest_sym_end_transition(s); */
435 ffest_sym_end_transition (ffesymbol s
)
437 return ffestu_sym_end_transition (s
);
440 /* ffest_sym_exec_transition -- Update symbol just before first exec stmt
443 ffest_sym_exec_transition(s); */
446 ffest_sym_exec_transition (ffesymbol s
)
448 return ffestu_sym_exec_transition (s
);
451 /* ffest_terminate_0 -- Terminate for entire image invocation
453 ffest_terminate_0(); */
458 ffesta_terminate_0 ();
459 ffestb_terminate_0 ();
460 ffestc_terminate_0 ();
461 ffestd_terminate_0 ();
462 ffeste_terminate_0 ();
463 ffestp_terminate_0 ();
464 ffestr_terminate_0 ();
465 ffests_terminate_0 ();
466 ffestt_terminate_0 ();
467 ffestu_terminate_0 ();
468 ffestv_terminate_0 ();
469 ffestw_terminate_0 ();
472 /* ffest_terminate_1 -- Terminate for source file
474 ffest_terminate_1(); */
479 ffesta_terminate_1 ();
480 ffestb_terminate_1 ();
481 ffestc_terminate_1 ();
482 ffestd_terminate_1 ();
483 ffeste_terminate_1 ();
484 ffestp_terminate_1 ();
485 ffestr_terminate_1 ();
486 ffests_terminate_1 ();
487 ffestt_terminate_1 ();
488 ffestu_terminate_1 ();
489 ffestv_terminate_1 ();
490 ffestw_terminate_1 ();
493 /* ffest_terminate_2 -- Terminate for outer program unit
495 ffest_terminate_2(); */
500 ffesta_terminate_2 ();
501 ffestb_terminate_2 ();
502 ffestc_terminate_2 ();
503 ffestd_terminate_2 ();
504 ffeste_terminate_2 ();
505 ffestp_terminate_2 ();
506 ffestr_terminate_2 ();
507 ffests_terminate_2 ();
508 ffestt_terminate_2 ();
509 ffestu_terminate_2 ();
510 ffestv_terminate_2 ();
511 ffestw_terminate_2 ();
514 /* ffest_terminate_3 -- Terminate for any program unit
516 ffest_terminate_3(); */
521 ffesta_terminate_3 ();
522 ffestb_terminate_3 ();
523 ffestc_terminate_3 ();
524 ffestd_terminate_3 ();
525 ffeste_terminate_3 ();
526 ffestp_terminate_3 ();
527 ffestr_terminate_3 ();
528 ffests_terminate_3 ();
529 ffestt_terminate_3 ();
530 ffestu_terminate_3 ();
531 ffestv_terminate_3 ();
532 ffestw_terminate_3 ();
535 /* ffest_terminate_4 -- Terminate for statement functions
537 ffest_terminate_4(); */
542 ffesta_terminate_4 ();
543 ffestb_terminate_4 ();
544 ffestc_terminate_4 ();
545 ffestd_terminate_4 ();
546 ffeste_terminate_4 ();
547 ffestp_terminate_4 ();
548 ffestr_terminate_4 ();
549 ffests_terminate_4 ();
550 ffestt_terminate_4 ();
551 ffestu_terminate_4 ();
552 ffestv_terminate_4 ();
553 ffestw_terminate_4 ();