Commit bd969772 by Neil Booth Committed by Neil Booth

cpphash.h (struct cpp_buffer): Move saved_flags from cpp_reader.

        * cpphash.h (struct cpp_buffer): Move saved_flags from cpp_reader.
        * cpplex.c (_cpp_lex_token): New token picks up the saved flags,
        and AVOID_LPASTE is cleared on meeting an unescaped newline.
        * cppmacro.c (builtin_macro): Set builtin flags here.
        (paste_all_tokens): Preserve AVOID_LPASTE on pasted token.
        (replace_args): Clarify intent.
        (cpp_get_token): Macro expansion tokens get the saved flags.
        Update.
        * cppmain.c (scan_buffer): Remove now-redundant print.printed
        check.

From-SVN: r39393
parent 8c0abc88
2001-02-01 Neil Booth <neil@daikokuya.demon.co.uk>
* cpphash.h (struct cpp_buffer): Move saved_flags from cpp_reader.
* cpplex.c (_cpp_lex_token): New token picks up the saved flags,
and AVOID_LPASTE is cleared on meeting an unescaped newline.
* cppmacro.c (builtin_macro): Set builtin flags here.
(paste_all_tokens): Preserve AVOID_LPASTE on pasted token.
(replace_args): Clarify intent.
(cpp_get_token): Macro expansion tokens get the saved flags.
Update.
* cppmain.c (scan_buffer): Remove now-redundant print.printed
check.
2001-02-01 Jeffrey Oldham <oldham@codesourcery.com> 2001-02-01 Jeffrey Oldham <oldham@codesourcery.com>
* config/mips/iris6.h (SUPPORTS_INIT_PRIORITY): Reverse change of * config/mips/iris6.h (SUPPORTS_INIT_PRIORITY): Reverse change of
......
...@@ -194,6 +194,9 @@ struct cpp_buffer ...@@ -194,6 +194,9 @@ struct cpp_buffer
/* Line number at line_base (above). */ /* Line number at line_base (above). */
unsigned int lineno; unsigned int lineno;
/* Contains PREV_WHITE and/or AVOID_LPASTE. */
unsigned char saved_flags;
/* Because of the way the lexer works, -Wtrigraphs can sometimes /* Because of the way the lexer works, -Wtrigraphs can sometimes
warn twice for the same trigraph. This helps prevent that. */ warn twice for the same trigraph. This helps prevent that. */
const unsigned char *last_Wtrigraphs; const unsigned char *last_Wtrigraphs;
...@@ -331,9 +334,6 @@ struct cpp_reader ...@@ -331,9 +334,6 @@ struct cpp_reader
/* We're printed a warning recommending against using #import. */ /* We're printed a warning recommending against using #import. */
unsigned char import_warning; unsigned char import_warning;
/* Used to flag the token after a paste AVOID_LPASTE. */
unsigned char saved_flags;
/* True after cpp_start_read completes. Used to inhibit some /* True after cpp_start_read completes. Used to inhibit some
warnings while parsing the command line. */ warnings while parsing the command line. */
unsigned char done_initializing; unsigned char done_initializing;
......
...@@ -857,7 +857,8 @@ _cpp_lex_token (pfile, result) ...@@ -857,7 +857,8 @@ _cpp_lex_token (pfile, result)
done_directive: done_directive:
buffer = pfile->buffer; buffer = pfile->buffer;
pfile->state.next_bol = 0; pfile->state.next_bol = 0;
result->flags = 0; result->flags = buffer->saved_flags;
buffer->saved_flags = 0;
next_char: next_char:
pfile->lexer_pos.line = buffer->lineno; pfile->lexer_pos.line = buffer->lineno;
next_char2: next_char2:
...@@ -899,7 +900,7 @@ _cpp_lex_token (pfile, result) ...@@ -899,7 +900,7 @@ _cpp_lex_token (pfile, result)
/* This is a new line, so clear any white space flag. /* This is a new line, so clear any white space flag.
Newlines in arguments are white space (6.10.3.10); Newlines in arguments are white space (6.10.3.10);
parse_arg takes care of that. */ parse_arg takes care of that. */
result->flags &= ~PREV_WHITE; result->flags &= ~(PREV_WHITE | AVOID_LPASTE);
goto next_char; goto next_char;
} }
...@@ -1196,7 +1197,7 @@ _cpp_lex_token (pfile, result) ...@@ -1196,7 +1197,7 @@ _cpp_lex_token (pfile, result)
/* Get whitespace right - newline_in_args sets it. */ /* Get whitespace right - newline_in_args sets it. */
if (pfile->lexer_pos.col == 1) if (pfile->lexer_pos.col == 1)
result->flags &= ~PREV_WHITE; result->flags &= ~(PREV_WHITE | AVOID_LPASTE);
} }
else else
{ {
......
...@@ -146,6 +146,7 @@ builtin_macro (pfile, token) ...@@ -146,6 +146,7 @@ builtin_macro (pfile, token)
cpp_reader *pfile; cpp_reader *pfile;
cpp_token *token; cpp_token *token;
{ {
unsigned char flags = ((token->flags & PREV_WHITE) | AVOID_LPASTE);
cpp_hashnode *node = token->val.node; cpp_hashnode *node = token->val.node;
switch (node->value.builtin) switch (node->value.builtin)
...@@ -219,6 +220,8 @@ builtin_macro (pfile, token) ...@@ -219,6 +220,8 @@ builtin_macro (pfile, token)
cpp_ice (pfile, "invalid builtin macro \"%s\"", node->name); cpp_ice (pfile, "invalid builtin macro \"%s\"", node->name);
break; break;
} }
token->flags = flags;
} }
/* Used by cpperror.c to obtain the correct line and column to report /* Used by cpperror.c to obtain the correct line and column to report
...@@ -458,7 +461,7 @@ paste_all_tokens (pfile, lhs) ...@@ -458,7 +461,7 @@ paste_all_tokens (pfile, lhs)
/* The pasted token has the PREV_WHITE flag of the LHS, is no longer /* The pasted token has the PREV_WHITE flag of the LHS, is no longer
PASTE_LEFT, and is subject to macro expansion. */ PASTE_LEFT, and is subject to macro expansion. */
lhs->flags &= ~(PREV_WHITE | PASTE_LEFT | NO_EXPAND); lhs->flags &= ~(PREV_WHITE | PASTE_LEFT | NO_EXPAND);
lhs->flags |= orig_flags & PREV_WHITE; lhs->flags |= orig_flags & (PREV_WHITE | AVOID_LPASTE);
} }
/* Reads the unexpanded tokens of a macro argument into ARG. VAR_ARGS /* Reads the unexpanded tokens of a macro argument into ARG. VAR_ARGS
...@@ -798,11 +801,11 @@ replace_args (pfile, macro, args, list) ...@@ -798,11 +801,11 @@ replace_args (pfile, macro, args, list)
/* The first token gets PREV_WHITE of the CPP_MACRO_ARG. */ /* The first token gets PREV_WHITE of the CPP_MACRO_ARG. */
dest->flags &= ~PREV_WHITE; dest->flags &= ~PREV_WHITE;
dest->flags |= src->flags & PREV_WHITE; dest->flags |= src->flags & PREV_WHITE;
dest->flags |= AVOID_LPASTE;
/* The last token gets the PASTE_LEFT of the CPP_MACRO_ARG. */ /* The last token gets the PASTE_LEFT of the CPP_MACRO_ARG. */
dest[count - 1].flags |= src->flags & PASTE_LEFT; dest[count - 1].flags |= src->flags & PASTE_LEFT;
dest[0].flags |= AVOID_LPASTE;
dest += count; dest += count;
} }
...@@ -906,10 +909,6 @@ cpp_get_token (pfile, token) ...@@ -906,10 +909,6 @@ cpp_get_token (pfile, token)
cpp_reader *pfile; cpp_reader *pfile;
cpp_token *token; cpp_token *token;
{ {
unsigned char flags = pfile->saved_flags;
pfile->saved_flags = 0;
for (;;) for (;;)
{ {
cpp_context *context = pfile->context; cpp_context *context = pfile->context;
...@@ -922,11 +921,13 @@ cpp_get_token (pfile, token) ...@@ -922,11 +921,13 @@ cpp_get_token (pfile, token)
else if (context->list.first != context->list.limit) else if (context->list.first != context->list.limit)
{ {
*token = *context->list.first++; *token = *context->list.first++;
token->flags |= pfile->buffer->saved_flags;
pfile->buffer->saved_flags = 0;
/* PASTE_LEFT tokens can only appear in macro expansions. */ /* PASTE_LEFT tokens can only appear in macro expansions. */
if (token->flags & PASTE_LEFT) if (token->flags & PASTE_LEFT)
{ {
paste_all_tokens (pfile, token); paste_all_tokens (pfile, token);
pfile->saved_flags = AVOID_LPASTE; pfile->buffer->saved_flags = AVOID_LPASTE;
} }
} }
else else
...@@ -934,7 +935,7 @@ cpp_get_token (pfile, token) ...@@ -934,7 +935,7 @@ cpp_get_token (pfile, token)
if (context->macro) if (context->macro)
{ {
/* Avoid accidental paste at the end of a macro. */ /* Avoid accidental paste at the end of a macro. */
flags |= AVOID_LPASTE; pfile->buffer->saved_flags |= AVOID_LPASTE;
_cpp_pop_context (pfile); _cpp_pop_context (pfile);
continue; continue;
} }
...@@ -944,8 +945,6 @@ cpp_get_token (pfile, token) ...@@ -944,8 +945,6 @@ cpp_get_token (pfile, token)
return; return;
} }
token->flags |= flags;
flags = 0;
if (token->type != CPP_NAME) if (token->type != CPP_NAME)
break; break;
...@@ -959,21 +958,22 @@ cpp_get_token (pfile, token) ...@@ -959,21 +958,22 @@ cpp_get_token (pfile, token)
/* Macros invalidate controlling macros. */ /* Macros invalidate controlling macros. */
pfile->mi_state = MI_FAILED; pfile->mi_state = MI_FAILED;
/* Remember PREV_WHITE and avoid an accidental paste. */
flags = (token->flags & PREV_WHITE) | AVOID_LPASTE;
if (node->flags & NODE_BUILTIN) if (node->flags & NODE_BUILTIN)
{ {
builtin_macro (pfile, token); builtin_macro (pfile, token);
token->flags = flags;
break; break;
} }
if (node->value.macro->disabled) if (node->value.macro->disabled)
token->flags |= NO_EXPAND; token->flags |= NO_EXPAND;
else if (enter_macro_context (pfile, node)) else if (enter_macro_context (pfile, node))
{
/* Pass AVOID_LPASTE and our PREV_WHITE to next token. */
pfile->buffer->saved_flags = ((token->flags & PREV_WHITE)
| AVOID_LPASTE);
continue; continue;
} }
}
/* Don't interpret _Pragma within directives. The standard is /* Don't interpret _Pragma within directives. The standard is
not clear on this, but to me this makes most sense. */ not clear on this, but to me this makes most sense. */
......
...@@ -234,8 +234,7 @@ scan_buffer (pfile) ...@@ -234,8 +234,7 @@ scan_buffer (pfile)
putc (' ', print.outf); putc (' ', print.outf);
} }
} }
else if (print.printed else if ((token->flags & (PREV_WHITE | AVOID_LPASTE))
&& (token->flags & (PREV_WHITE | AVOID_LPASTE))
== AVOID_LPASTE == AVOID_LPASTE
&& cpp_avoid_paste (pfile, &tokens[1 - index], token)) && cpp_avoid_paste (pfile, &tokens[1 - index], token))
token->flags |= PREV_WHITE; token->flags |= PREV_WHITE;
......
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