Commit 601328bb by Neil Booth Committed by Neil Booth

cpphash.h (cpp_macro): Move here, and make expansion a union.

	* cpphash.h (cpp_macro): Move here, and make expansion a union.
	* cppmacro.c (cpp_macro): Remove.
	(enter_macro_context, replace_args, warn_of_redefinition,
	_cpp_create_definition, cpp_macro_definition): Update.

From-SVN: r53509
parent f4b251a6
2002-05-16 Neil Booth <neil@daikokuya.demon.co.uk>
* cpphash.h (cpp_macro): Move here, and make expansion a union.
* cppmacro.c (cpp_macro): Remove.
(enter_macro_context, replace_args, warn_of_redefinition,
_cpp_create_definition, cpp_macro_definition): Update.
2002-05-16 Jason Merrill <jason@redhat.com> 2002-05-16 Jason Merrill <jason@redhat.com>
* config/mips/mips.c (mips_output_external): Don't do sdata * config/mips/mips.c (mips_output_external): Don't do sdata
......
...@@ -29,6 +29,9 @@ struct directive; /* Deliberately incomplete. */ ...@@ -29,6 +29,9 @@ struct directive; /* Deliberately incomplete. */
struct pending_option; struct pending_option;
struct op; struct op;
typedef unsigned char uchar;
#define U (const uchar *) /* Intended use: U"string" */
#define BITS_PER_CPPCHAR_T (CHAR_BIT * sizeof (cppchar_t)) #define BITS_PER_CPPCHAR_T (CHAR_BIT * sizeof (cppchar_t))
/* Test if a sign is valid within a preprocessing number. */ /* Test if a sign is valid within a preprocessing number. */
...@@ -47,6 +50,24 @@ struct op; ...@@ -47,6 +50,24 @@ struct op;
efficiency, and partly to limit runaway recursion. */ efficiency, and partly to limit runaway recursion. */
#define CPP_STACK_MAX 200 #define CPP_STACK_MAX 200
/* Each macro definition is recorded in a cpp_macro structure.
Variadic macros cannot occur with traditional cpp. */
struct cpp_macro
{
cpp_hashnode **params; /* Parameters, if any. */
union
{
cpp_token *tokens; /* Tokens of replacement list (ISO). */
const uchar *text; /* Expansion text (traditional). */
} exp;
unsigned int line; /* Starting line number. */
unsigned int count; /* Number of tokens / bytes in expansion. */
unsigned short paramc; /* Number of parameters. */
unsigned int fun_like : 1; /* If a function-like macro. */
unsigned int variadic : 1; /* If a variadic macro. */
unsigned int syshdr : 1; /* If macro defined in system header. */
};
/* A generic memory buffer, and operations on it. */ /* A generic memory buffer, and operations on it. */
typedef struct _cpp_buff _cpp_buff; typedef struct _cpp_buff _cpp_buff;
struct _cpp_buff struct _cpp_buff
...@@ -436,9 +457,6 @@ extern void _cpp_pop_buffer PARAMS ((cpp_reader *)); ...@@ -436,9 +457,6 @@ extern void _cpp_pop_buffer PARAMS ((cpp_reader *));
/* These are inline functions instead of macros so we can get type /* These are inline functions instead of macros so we can get type
checking. */ checking. */
typedef unsigned char uchar;
#define U (const uchar *) /* Intended use: U"string" */
static inline int ustrcmp PARAMS ((const uchar *, const uchar *)); static inline int ustrcmp PARAMS ((const uchar *, const uchar *));
static inline int ustrncmp PARAMS ((const uchar *, const uchar *, static inline int ustrncmp PARAMS ((const uchar *, const uchar *,
size_t)); size_t));
......
...@@ -28,18 +28,6 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ...@@ -28,18 +28,6 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "cpplib.h" #include "cpplib.h"
#include "cpphash.h" #include "cpphash.h"
struct cpp_macro
{
cpp_hashnode **params; /* Parameters, if any. */
cpp_token *expansion; /* First token of replacement list. */
unsigned int line; /* Starting line number. */
unsigned int count; /* Number of tokens in expansion. */
unsigned short paramc; /* Number of parameters. */
unsigned int fun_like : 1; /* If a function-like macro. */
unsigned int variadic : 1; /* If a variadic macro. */
unsigned int syshdr : 1; /* If macro defined in system header. */
};
typedef struct macro_arg macro_arg; typedef struct macro_arg macro_arg;
struct macro_arg struct macro_arg
{ {
...@@ -695,7 +683,7 @@ enter_macro_context (pfile, node) ...@@ -695,7 +683,7 @@ enter_macro_context (pfile, node)
node->flags |= NODE_DISABLED; node->flags |= NODE_DISABLED;
if (macro->paramc == 0) if (macro->paramc == 0)
push_token_context (pfile, node, macro->expansion, macro->count); push_token_context (pfile, node, macro->exp.tokens, macro->count);
return 1; return 1;
} }
...@@ -726,9 +714,9 @@ replace_args (pfile, node, macro, args) ...@@ -726,9 +714,9 @@ replace_args (pfile, node, macro, args)
statements below is subtle; we must handle stringification before statements below is subtle; we must handle stringification before
pasting. */ pasting. */
total = macro->count; total = macro->count;
limit = macro->expansion + macro->count; limit = macro->exp.tokens + macro->count;
for (src = macro->expansion; src < limit; src++) for (src = macro->exp.tokens; src < limit; src++)
if (src->type == CPP_MACRO_ARG) if (src->type == CPP_MACRO_ARG)
{ {
/* Leading and trailing padding tokens. */ /* Leading and trailing padding tokens. */
...@@ -744,7 +732,7 @@ replace_args (pfile, node, macro, args) ...@@ -744,7 +732,7 @@ replace_args (pfile, node, macro, args)
arg->stringified = stringify_arg (pfile, arg); arg->stringified = stringify_arg (pfile, arg);
} }
else if ((src->flags & PASTE_LEFT) else if ((src->flags & PASTE_LEFT)
|| (src > macro->expansion && (src[-1].flags & PASTE_LEFT))) || (src > macro->exp.tokens && (src[-1].flags & PASTE_LEFT)))
total += arg->count - 1; total += arg->count - 1;
else else
{ {
...@@ -760,7 +748,7 @@ replace_args (pfile, node, macro, args) ...@@ -760,7 +748,7 @@ replace_args (pfile, node, macro, args)
first = (const cpp_token **) buff->base; first = (const cpp_token **) buff->base;
dest = first; dest = first;
for (src = macro->expansion; src < limit; src++) for (src = macro->exp.tokens; src < limit; src++)
{ {
unsigned int count; unsigned int count;
const cpp_token **from, **paste_flag; const cpp_token **from, **paste_flag;
...@@ -777,7 +765,7 @@ replace_args (pfile, node, macro, args) ...@@ -777,7 +765,7 @@ replace_args (pfile, node, macro, args)
count = 1, from = &arg->stringified; count = 1, from = &arg->stringified;
else if (src->flags & PASTE_LEFT) else if (src->flags & PASTE_LEFT)
count = arg->count, from = arg->first; count = arg->count, from = arg->first;
else if (src != macro->expansion && (src[-1].flags & PASTE_LEFT)) else if (src != macro->exp.tokens && (src[-1].flags & PASTE_LEFT))
{ {
count = arg->count, from = arg->first; count = arg->count, from = arg->first;
if (dest != first) if (dest != first)
...@@ -805,7 +793,7 @@ replace_args (pfile, node, macro, args) ...@@ -805,7 +793,7 @@ replace_args (pfile, node, macro, args)
/* Padding on the left of an argument (unless RHS of ##). */ /* Padding on the left of an argument (unless RHS of ##). */
if (!pfile->state.in_directive if (!pfile->state.in_directive
&& src != macro->expansion && !(src[-1].flags & PASTE_LEFT)) && src != macro->exp.tokens && !(src[-1].flags & PASTE_LEFT))
*dest++ = padding_token (pfile, src); *dest++ = padding_token (pfile, src);
if (count) if (count)
...@@ -1149,7 +1137,7 @@ warn_of_redefinition (node, macro2) ...@@ -1149,7 +1137,7 @@ warn_of_redefinition (node, macro2)
/* Check each token. */ /* Check each token. */
for (i = 0; i < macro1->count; i++) for (i = 0; i < macro1->count; i++)
if (! _cpp_equiv_tokens (&macro1->expansion[i], &macro2->expansion[i])) if (! _cpp_equiv_tokens (&macro1->exp.tokens[i], &macro2->exp.tokens[i]))
return 1; return 1;
/* Check parameter spellings. */ /* Check parameter spellings. */
...@@ -1410,22 +1398,22 @@ _cpp_create_definition (pfile, node) ...@@ -1410,22 +1398,22 @@ _cpp_create_definition (pfile, node)
token = lex_expansion_token (pfile, macro); token = lex_expansion_token (pfile, macro);
} }
macro->expansion = (cpp_token *) BUFF_FRONT (pfile->a_buff); macro->exp.tokens = (cpp_token *) BUFF_FRONT (pfile->a_buff);
/* Don't count the CPP_EOF. */ /* Don't count the CPP_EOF. */
macro->count--; macro->count--;
/* Clear whitespace on first token for warn_of_redefinition(). */ /* Clear whitespace on first token for warn_of_redefinition(). */
if (macro->count) if (macro->count)
macro->expansion[0].flags &= ~PREV_WHITE; macro->exp.tokens[0].flags &= ~PREV_WHITE;
/* Commit the memory. */ /* Commit the memory. */
BUFF_FRONT (pfile->a_buff) = (uchar *) &macro->expansion[macro->count]; BUFF_FRONT (pfile->a_buff) = (uchar *) &macro->exp.tokens[macro->count];
/* Implement the macro-defined-to-itself optimisation. */ /* Implement the macro-defined-to-itself optimisation. */
if (macro->count == 1 && !macro->fun_like if (macro->count == 1 && !macro->fun_like
&& macro->expansion[0].type == CPP_NAME && macro->exp.tokens[0].type == CPP_NAME
&& macro->expansion[0].val.node == node) && macro->exp.tokens[0].val.node == node)
node->flags |= NODE_DISABLED; node->flags |= NODE_DISABLED;
/* To suppress some diagnostics. */ /* To suppress some diagnostics. */
...@@ -1545,7 +1533,7 @@ cpp_macro_definition (pfile, node) ...@@ -1545,7 +1533,7 @@ cpp_macro_definition (pfile, node)
for (i = 0; i < macro->count; i++) for (i = 0; i < macro->count; i++)
{ {
cpp_token *token = &macro->expansion[i]; cpp_token *token = &macro->exp.tokens[i];
if (token->type == CPP_MACRO_ARG) if (token->type == CPP_MACRO_ARG)
len += NODE_LEN (macro->params[token->val.arg_no - 1]); len += NODE_LEN (macro->params[token->val.arg_no - 1]);
...@@ -1602,7 +1590,7 @@ cpp_macro_definition (pfile, node) ...@@ -1602,7 +1590,7 @@ cpp_macro_definition (pfile, node)
{ {
for (i = 0; i < macro->count; i++) for (i = 0; i < macro->count; i++)
{ {
cpp_token *token = &macro->expansion[i]; cpp_token *token = &macro->exp.tokens[i];
if (token->flags & PREV_WHITE) if (token->flags & PREV_WHITE)
*buffer++ = ' '; *buffer++ = ' ';
......
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