Commit b528a07e by Neil Booth Committed by Neil Booth

cppexp.c: Don't worry about pfile->skipping.

        * cppexp.c: Don't worry about pfile->skipping.
        * cpplib.c (struct if_stack): Make was_skipping unsigned char.
        (cpp_handle_directive): Save pfile->skipping in struct cpp_buffer
        for handled directives.
        (skip_rest_of_line): Use _cpp_lex_token after popping contexts
        and releasing lookaheads.
        (do_ifdef, do_ifndef, do_if): Use buffer->was_skipping.
        (do_else, do_elif, push_conditional): Update logic.
        (do_endif): Set buffer->was_skipping rather than pfile->skipping.
        (unwind_if_stack): Inline into cpp_pop_buffer.
        (cpp_push_buffer): Clear ifs->was_skipping for cpp_handle_directive.
        * cpplex.c (_cpp_lex_token): Clear skipping on EOF.  Handle
        multiple-include optimisation.
        * cpplib.h (struct cpp_buffer): New member was_skipping.
        * cppmacro.c (_cpp_get_token): Loop whilst pfile->skipping.  This
        works because skipping == 0 in directives.
        (_cpp_release_lookahead): Renamed from release_lookahead.
        (cpp_get_token): No need to check skipping as _cpp_get_token does
        this for us.  No need to handle MI optimisation.

From-SVN: r37404
parent 46bdc296
2000-11-12 Neil Booth <neilb@earthling.net>
* cppexp.c: Don't worry about pfile->skipping.
* cpplib.c (struct if_stack): Make was_skipping unsigned char.
(cpp_handle_directive): Save pfile->skipping in struct cpp_buffer
for handled directives.
(skip_rest_of_line): Use _cpp_lex_token after popping contexts
and releasing lookaheads.
(do_ifdef, do_ifndef, do_if): Use buffer->was_skipping.
(do_else, do_elif, push_conditional): Update logic.
(do_endif): Set buffer->was_skipping rather than pfile->skipping.
(unwind_if_stack): Inline into cpp_pop_buffer.
(cpp_push_buffer): Clear ifs->was_skipping for cpp_handle_directive.
* cpplex.c (_cpp_lex_token): Clear skipping on EOF. Handle
multiple-include optimisation.
* cpplib.h (struct cpp_buffer): New member was_skipping.
* cppmacro.c (_cpp_get_token): Loop whilst pfile->skipping. This
works because skipping == 0 in directives.
(_cpp_release_lookahead): Renamed from release_lookahead.
(cpp_get_token): No need to check skipping as _cpp_get_token does
this for us. No need to handle MI optimisation.
Sat Nov 11 21:14:02 2000 Mark P Mitchell <mark@codesourcery.com>
* fixinc/inclhack.def (sunos_matherr_decl): Bypass matherr
......
......@@ -752,10 +752,6 @@ _cpp_parse_expr (pfile)
int skip_evaluation = 0;
int result;
/* Save parser state and set it to something sane. */
int save_skipping = pfile->skipping;
pfile->skipping = 0;
/* Set up detection of #if ! defined(). */
pfile->mi_lexed = 0;
pfile->mi_if_not_defined = MI_IND_NONE;
......@@ -1039,7 +1035,6 @@ _cpp_parse_expr (pfile)
/* Free dynamic stack if we allocated one. */
if (stack != init_stack)
free (stack);
pfile->skipping = save_skipping;
return result;
}
......
......@@ -160,6 +160,7 @@ extern int _cpp_create_definition PARAMS ((cpp_reader *, cpp_hashnode *));
extern void _cpp_pop_context PARAMS ((cpp_reader *));
extern void _cpp_get_token PARAMS ((cpp_reader *, cpp_token *));
extern void _cpp_free_lookaheads PARAMS ((cpp_reader *));
extern void _cpp_release_lookahead PARAMS ((cpp_reader *));
extern void _cpp_push_token PARAMS ((cpp_reader *, const cpp_token *,
const cpp_lexer_pos *));
......
......@@ -874,6 +874,7 @@ _cpp_lex_token (pfile, result)
if (pfile->lexer_pos.col != 0 && !buffer->from_stage3)
cpp_pedwarn (pfile, "no newline at end of file");
pfile->state.next_bol = 1;
pfile->skipping = 0; /* In case missing #endif. */
result->type = CPP_EOF;
break;
......@@ -1270,6 +1271,12 @@ _cpp_lex_token (pfile, result)
result->val.c = c;
break;
}
/* Non-comment tokens invalidate any controlling macros. */
if (result->type != CPP_COMMENT
&& result->type != CPP_EOF
&& !pfile->state.in_directive)
pfile->mi_state = MI_FAILED;
}
/* An upper bound on the number of bytes needed to spell a token,
......
......@@ -290,6 +290,9 @@ struct cpp_buffer
for preprocessed input, command line directives, and _Pragma
buffers. */
unsigned char from_stage3;
/* Temporary storage for pfile->skipping whilst in a directive. */
unsigned char was_skipping;
};
/* Maximum nesting of cpp_buffers. We use a static limit, partly for
......
......@@ -86,7 +86,6 @@ static void replace_args PARAMS ((cpp_reader *, cpp_macro *, macro_arg *,
static void save_lookahead_token PARAMS ((cpp_reader *, const cpp_token *));
static void take_lookahead_token PARAMS ((cpp_reader *, cpp_token *));
static void release_lookahead PARAMS ((cpp_reader *));
static cpp_lookahead *alloc_lookahead PARAMS ((cpp_reader *));
static void free_lookahead PARAMS ((cpp_lookahead *));
......@@ -897,7 +896,7 @@ _cpp_get_token (pfile, token)
cpp_token *token;
{
next_token:
for (;;)
do
{
cpp_context *context = pfile->context;
......@@ -913,22 +912,15 @@ _cpp_get_token (pfile, token)
if (context->macro)
{
_cpp_pop_context (pfile);
continue;
goto next_token;
}
/* End of argument pre-expansion. */
token->type = CPP_EOF;
token->flags = 0;
return;
}
break;
}
/* Only perform macro expansion (and therefore pasting) when not
skipping, or when skipping but in a directive. The only
directive where this could be true is #elif. A possible later
optimisation: get do_elif to clear skipping so we don't need the
directive test here. */
if (pfile->skipping && !pfile->state.in_directive)
return;
while (pfile->skipping);
for (;;)
{
......@@ -985,22 +977,8 @@ cpp_get_token (pfile, token)
cpp_reader *pfile;
cpp_token *token;
{
for (;;)
{
_cpp_get_token (pfile, token);
if (token->type == CPP_EOF)
break;
else if (pfile->skipping)
continue;
/* Non-comment tokens invalidate any controlling macros. */
if (token->type != CPP_COMMENT)
pfile->mi_state = MI_FAILED;
break;
}
if (pfile->la_write)
save_lookahead_token (pfile, token);
}
......@@ -1057,12 +1035,12 @@ take_lookahead_token (pfile, token)
pfile->lexer_pos = twp->pos;
if (++la->cur == la->count)
release_lookahead (pfile);
_cpp_release_lookahead (pfile);
}
/* Moves the lookahead at the front of the read list to the free store. */
static void
release_lookahead (pfile)
void
_cpp_release_lookahead (pfile)
cpp_reader *pfile;
{
cpp_lookahead *la = pfile->la_read;
......@@ -1151,7 +1129,7 @@ cpp_stop_lookahead (pfile, drop)
pfile->la_read = la;
if (drop || la->count == 0)
release_lookahead (pfile);
_cpp_release_lookahead (pfile);
else
pfile->lexer_pos = la->pos;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment