Commit 29b10746 by Neil Booth Committed by Neil Booth

cpplex.c (_cpp_lex_token): CPP_COMMENT and true CPP_EOF cases return without MI check.

        * cpplex.c (_cpp_lex_token): CPP_COMMENT and true CPP_EOF
        cases return without MI check.
        * cpplib.c (do_diagnostic): Take boolean of whether to
        print the directive name.
        (do_error, do_warning): Update.
        (do_pragma_dependency): Use it.
        * cpplib.h (VARARGS_FIRST): Delete.
        (struct cpp_token): Delete integer.
        * cppmacro.c (enter_macro_context): Move disabled check
        to _cpp_get_token.
        (_cpp_get_token): Simplify into a single loop.

From-SVN: r37434
parent eb68ad7c
2000-11-13 Neil Booth <neilb@earthling.net>
* cpplex.c (_cpp_lex_token): CPP_COMMENT and true CPP_EOF
cases return without MI check.
* cpplib.c (do_diagnostic): Take boolean of whether to
print the directive name.
(do_error, do_warning): Update.
(do_pragma_dependency): Use it.
* cpplib.h (VARARGS_FIRST): Delete.
(struct cpp_token): Delete integer.
* cppmacro.c (enter_macro_context): Move disabled check
to _cpp_get_token.
(_cpp_get_token): Simplify into a single loop.
2000-11-13 Richard Earnshaw <rearnsha@arm.com> 2000-11-13 Richard Earnshaw <rearnsha@arm.com>
* configure.in: Use 'test -f' not '[ -e'. * configure.in: Use 'test -f' not '[ -e'.
......
...@@ -876,7 +876,8 @@ _cpp_lex_token (pfile, result) ...@@ -876,7 +876,8 @@ _cpp_lex_token (pfile, result)
pfile->state.next_bol = 1; pfile->state.next_bol = 1;
pfile->skipping = 0; /* In case missing #endif. */ pfile->skipping = 0; /* In case missing #endif. */
result->type = CPP_EOF; result->type = CPP_EOF;
break; /* Don't do MI optimisation. */
return;
case ' ': case '\t': case '\f': case '\v': case '\0': case ' ': case '\t': case '\f': case '\v': case '\0':
skip_whitespace (pfile, c); skip_whitespace (pfile, c);
...@@ -1032,7 +1033,8 @@ _cpp_lex_token (pfile, result) ...@@ -1032,7 +1033,8 @@ _cpp_lex_token (pfile, result)
/* Save the comment as a token in its own right. */ /* Save the comment as a token in its own right. */
save_comment (pfile, result, comment_start); save_comment (pfile, result, comment_start);
break; /* Don't do MI optimisation. */
return;
case '<': case '<':
if (pfile->state.angled_headers) if (pfile->state.angled_headers)
...@@ -1272,10 +1274,8 @@ _cpp_lex_token (pfile, result) ...@@ -1272,10 +1274,8 @@ _cpp_lex_token (pfile, result)
break; break;
} }
/* Non-comment tokens invalidate any controlling macros. */ /* If not in a directive, this token invalidates controlling macros. */
if (result->type != CPP_COMMENT if (!pfile->state.in_directive)
&& result->type != CPP_EOF
&& !pfile->state.in_directive)
pfile->mi_state = MI_FAILED; pfile->mi_state = MI_FAILED;
} }
......
...@@ -91,7 +91,7 @@ static void push_conditional PARAMS ((cpp_reader *, int, int, ...@@ -91,7 +91,7 @@ static void push_conditional PARAMS ((cpp_reader *, int, int,
static int read_line_number PARAMS ((cpp_reader *, int *)); static int read_line_number PARAMS ((cpp_reader *, int *));
static int strtoul_for_line PARAMS ((const U_CHAR *, unsigned int, static int strtoul_for_line PARAMS ((const U_CHAR *, unsigned int,
unsigned long *)); unsigned long *));
static void do_diagnostic PARAMS ((cpp_reader *, enum error_type)); static void do_diagnostic PARAMS ((cpp_reader *, enum error_type, int));
static cpp_hashnode *lex_macro_node PARAMS ((cpp_reader *)); static cpp_hashnode *lex_macro_node PARAMS ((cpp_reader *));
static void do_pragma_once PARAMS ((cpp_reader *)); static void do_pragma_once PARAMS ((cpp_reader *));
static void do_pragma_poison PARAMS ((cpp_reader *)); static void do_pragma_poison PARAMS ((cpp_reader *));
...@@ -792,13 +792,15 @@ do_line (pfile) ...@@ -792,13 +792,15 @@ do_line (pfile)
*/ */
static void static void
do_diagnostic (pfile, code) do_diagnostic (pfile, code, print_dir)
cpp_reader *pfile; cpp_reader *pfile;
enum error_type code; enum error_type code;
int print_dir;
{ {
if (_cpp_begin_message (pfile, code, NULL, 0)) if (_cpp_begin_message (pfile, code, NULL, 0))
{ {
fprintf (stderr, "#%s ", pfile->directive->name); if (print_dir)
fprintf (stderr, "#%s ", pfile->directive->name);
pfile->state.prevent_expansion++; pfile->state.prevent_expansion++;
cpp_output_line (pfile, stderr); cpp_output_line (pfile, stderr);
pfile->state.prevent_expansion--; pfile->state.prevent_expansion--;
...@@ -809,14 +811,14 @@ static void ...@@ -809,14 +811,14 @@ static void
do_error (pfile) do_error (pfile)
cpp_reader *pfile; cpp_reader *pfile;
{ {
do_diagnostic (pfile, ERROR); do_diagnostic (pfile, ERROR, 1);
} }
static void static void
do_warning (pfile) do_warning (pfile)
cpp_reader *pfile; cpp_reader *pfile;
{ {
do_diagnostic (pfile, WARNING); do_diagnostic (pfile, WARNING, 1);
} }
/* Report program identification. */ /* Report program identification. */
...@@ -1085,8 +1087,8 @@ do_pragma_dependency (pfile) ...@@ -1085,8 +1087,8 @@ do_pragma_dependency (pfile)
cpp_start_lookahead (pfile); cpp_start_lookahead (pfile);
cpp_get_token (pfile, &msg); cpp_get_token (pfile, &msg);
cpp_stop_lookahead (pfile, msg.type == CPP_EOF); cpp_stop_lookahead (pfile, msg.type == CPP_EOF);
if (msg.type != CPP_EOF && _cpp_begin_message (pfile, WARNING, NULL, 0)) if (msg.type != CPP_EOF)
cpp_output_line (pfile, stderr); do_diagnostic (pfile, WARNING, 0);
} }
} }
......
...@@ -170,7 +170,6 @@ struct cpp_string ...@@ -170,7 +170,6 @@ struct cpp_string
#define PASTE_LEFT (1 << 3) /* If on LHS of a ## operator. */ #define PASTE_LEFT (1 << 3) /* If on LHS of a ## operator. */
#define NAMED_OP (1 << 4) /* C++ named operators, also "defined". */ #define NAMED_OP (1 << 4) /* C++ named operators, also "defined". */
#define NO_EXPAND (1 << 5) /* Do not macro-expand this token. */ #define NO_EXPAND (1 << 5) /* Do not macro-expand this token. */
#define VARARGS_FIRST STRINGIFY_ARG /* First token of varargs expansion. */
/* A preprocessing token. This has been carefully packed and should /* A preprocessing token. This has been carefully packed and should
occupy 12 bytes on 32-bit hosts and 16 bytes on 64-bit hosts. */ occupy 12 bytes on 32-bit hosts and 16 bytes on 64-bit hosts. */
...@@ -181,7 +180,6 @@ struct cpp_token ...@@ -181,7 +180,6 @@ struct cpp_token
union union
{ {
HOST_WIDEST_INT integer; /* An integer. */
struct cpp_hashnode *node; /* An identifier. */ struct cpp_hashnode *node; /* An identifier. */
struct cpp_string str; /* A string, or number. */ struct cpp_string str; /* A string, or number. */
unsigned int arg_no; /* Argument no. for a CPP_MACRO_ARG. */ unsigned int arg_no; /* Argument no. for a CPP_MACRO_ARG. */
......
...@@ -60,7 +60,7 @@ struct macro_arg ...@@ -60,7 +60,7 @@ struct macro_arg
static void lock_pools PARAMS ((cpp_reader *)); static void lock_pools PARAMS ((cpp_reader *));
static void unlock_pools PARAMS ((cpp_reader *)); static void unlock_pools PARAMS ((cpp_reader *));
static int enter_macro_context PARAMS ((cpp_reader *, cpp_token *)); static int enter_macro_context PARAMS ((cpp_reader *, cpp_hashnode *));
static void builtin_macro PARAMS ((cpp_reader *, cpp_token *)); static void builtin_macro PARAMS ((cpp_reader *, cpp_token *));
static cpp_context *push_arg_context PARAMS ((cpp_reader *, macro_arg *)); static cpp_context *push_arg_context PARAMS ((cpp_reader *, macro_arg *));
static enum cpp_ttype parse_arg PARAMS ((cpp_reader *, macro_arg *, int)); static enum cpp_ttype parse_arg PARAMS ((cpp_reader *, macro_arg *, int));
...@@ -631,22 +631,14 @@ funlike_invocation_p (pfile, node, list) ...@@ -631,22 +631,14 @@ funlike_invocation_p (pfile, node, list)
TOKEN is replaced with the first token of the expansion, and we TOKEN is replaced with the first token of the expansion, and we
return non-zero. */ return non-zero. */
static int static int
enter_macro_context (pfile, token) enter_macro_context (pfile, node)
cpp_reader *pfile; cpp_reader *pfile;
cpp_token *token; cpp_hashnode *node;
{ {
cpp_context *context; cpp_context *context;
cpp_macro *macro; cpp_macro *macro = node->value.macro;
unsigned char flags;
struct toklist list; struct toklist list;
macro = token->val.node->value.macro;
if (macro->disabled)
{
token->flags |= NO_EXPAND;
return 0;
}
/* Save the position of the outermost macro invocation. */ /* Save the position of the outermost macro invocation. */
if (!pfile->context->prev) if (!pfile->context->prev)
{ {
...@@ -654,7 +646,7 @@ enter_macro_context (pfile, token) ...@@ -654,7 +646,7 @@ enter_macro_context (pfile, token)
lock_pools (pfile); lock_pools (pfile);
} }
if (macro->fun_like && !funlike_invocation_p (pfile, token->val.node, &list)) if (macro->fun_like && !funlike_invocation_p (pfile, node, &list))
{ {
if (!pfile->context->prev) if (!pfile->context->prev)
unlock_pools (pfile); unlock_pools (pfile);
...@@ -667,22 +659,16 @@ enter_macro_context (pfile, token) ...@@ -667,22 +659,16 @@ enter_macro_context (pfile, token)
list.limit = macro->expansion + macro->count; list.limit = macro->expansion + macro->count;
} }
/* Temporary kludge. */ if (list.first != list.limit)
if (list.first == list.limit) {
return 2; /* Push its context. */
context = next_context (pfile);
/* Now push its context. */ context->list = list;
context = next_context (pfile); context->macro = macro;
context->list = list;
context->macro = macro;
/* The first expansion token inherits the PREV_WHITE of TOKEN. */
flags = token->flags & PREV_WHITE;
*token = *context->list.first++;
token->flags |= flags;
/* Disable the macro within its expansion. */ /* Disable the macro within its expansion. */
macro->disabled = 1; macro->disabled = 1;
}
return 1; return 1;
} }
...@@ -895,8 +881,9 @@ _cpp_get_token (pfile, token) ...@@ -895,8 +881,9 @@ _cpp_get_token (pfile, token)
cpp_reader *pfile; cpp_reader *pfile;
cpp_token *token; cpp_token *token;
{ {
next_token: unsigned char flags = 0;
do
for (;;)
{ {
cpp_context *context = pfile->context; cpp_context *context = pfile->context;
...@@ -906,24 +893,28 @@ _cpp_get_token (pfile, token) ...@@ -906,24 +893,28 @@ _cpp_get_token (pfile, token)
else if (!context->prev) else if (!context->prev)
_cpp_lex_token (pfile, token); _cpp_lex_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 |= flags;
flags = 0;
}
else else
{ {
if (context->macro) if (context->macro)
{ {
_cpp_pop_context (pfile); _cpp_pop_context (pfile);
goto next_token; continue;
} }
/* End of argument pre-expansion. */ /* End of argument pre-expansion. */
token->type = CPP_EOF; token->type = CPP_EOF;
token->flags = 0; token->flags = 0;
return; return;
} }
}
while (pfile->skipping);
for (;;) /* Loop until we're not skipping. */
{ if (pfile->skipping)
continue;
if (token->flags & PASTE_LEFT) if (token->flags & PASTE_LEFT)
paste_all_tokens (pfile, token); paste_all_tokens (pfile, token);
...@@ -935,31 +926,32 @@ _cpp_get_token (pfile, token) ...@@ -935,31 +926,32 @@ _cpp_get_token (pfile, token)
&& !pfile->state.prevent_expansion && !pfile->state.prevent_expansion
&& !(token->flags & NO_EXPAND)) && !(token->flags & NO_EXPAND))
{ {
int m; cpp_hashnode *node = token->val.node;
/* Macros invalidate controlling macros. */ /* Macros invalidate controlling macros. */
pfile->mi_state = MI_FAILED; pfile->mi_state = MI_FAILED;
if (token->val.node->flags & NODE_BUILTIN) if (node->flags & NODE_BUILTIN)
{ {
builtin_macro (pfile, token); builtin_macro (pfile, token);
break; break;
} }
m = enter_macro_context (pfile, token); /* Merge PREV_WHITE of tokens. */
if (m == 1) flags = token->flags & PREV_WHITE;
if (node->value.macro->disabled)
token->flags |= NO_EXPAND;
else if (enter_macro_context (pfile, node))
continue; continue;
if (m == 2)
goto next_token;
} }
if (token->val.node != pfile->spec_nodes.n__Pragma) if (token->val.node != pfile->spec_nodes.n__Pragma)
break; break;
/* Invalidate controlling macros. */ /* Handle it, and get another token. */
pfile->mi_state = MI_FAILED; pfile->mi_state = MI_FAILED;
_cpp_do__Pragma (pfile); _cpp_do__Pragma (pfile);
goto next_token;
} }
} }
......
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