mirror of
git://gcc.gnu.org/git/gcc.git
synced 2025-02-25 02:25:31 +08:00
cpphash.h: Update comment.
* cpphash.h: Update comment. * cpplex.c: Update comments. (_cpp_can_paste): Remove. * cpplib.h (_cpp_can_paste): Remove. * cppmacro.c (paste_tokens, paste_all_tokens): Update to use the lexer rather than _cpp_can_paste. From-SVN: r45840
This commit is contained in:
parent
4cf817a7eb
commit
c9e7a60950
@ -1,3 +1,12 @@
|
||||
2001-09-27 Neil Booth <neil@daikokuya.demon.co.uk>
|
||||
|
||||
* cpphash.h: Update comment.
|
||||
* cpplex.c: Update comments.
|
||||
(_cpp_can_paste): Remove.
|
||||
* cpplib.h (_cpp_can_paste): Remove.
|
||||
* cppmacro.c (paste_tokens, paste_all_tokens): Update to use the
|
||||
lexer rather than _cpp_can_paste.
|
||||
|
||||
2001-09-27 Neil Booth <neil@daikokuya.demon.co.uk>
|
||||
|
||||
* doc/cppinternals.texi: Update.
|
||||
|
@ -134,7 +134,7 @@ struct cpp_context
|
||||
union utoken last;
|
||||
|
||||
/* If non-NULL, a buffer used for storage related to this context.
|
||||
When the context is popped, the buffer is freed. */
|
||||
When the context is popped, the buffer is released. */
|
||||
_cpp_buff *buff;
|
||||
|
||||
/* For a macro context, these are the macro and its arguments. */
|
||||
|
110
gcc/cpplex.c
110
gcc/cpplex.c
@ -1218,7 +1218,6 @@ _cpp_lex_direct (pfile)
|
||||
|
||||
/* Save the comment as a token in its own right. */
|
||||
save_comment (pfile, result, comment_start);
|
||||
/* Don't do MI optimisation. */
|
||||
break;
|
||||
|
||||
case '<':
|
||||
@ -1588,112 +1587,6 @@ _cpp_equiv_tokens (a, b)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Determine whether two tokens can be pasted together, and if so,
|
||||
what the resulting token is. Returns CPP_EOF if the tokens cannot
|
||||
be pasted, or the appropriate type for the merged token if they
|
||||
can. */
|
||||
enum cpp_ttype
|
||||
cpp_can_paste (pfile, token1, token2, digraph)
|
||||
cpp_reader * pfile;
|
||||
const cpp_token *token1, *token2;
|
||||
int* digraph;
|
||||
{
|
||||
enum cpp_ttype a = token1->type, b = token2->type;
|
||||
int cxx = CPP_OPTION (pfile, cplusplus);
|
||||
|
||||
/* Treat named operators as if they were ordinary NAMEs. */
|
||||
if (token1->flags & NAMED_OP)
|
||||
a = CPP_NAME;
|
||||
if (token2->flags & NAMED_OP)
|
||||
b = CPP_NAME;
|
||||
|
||||
if ((int) a <= (int) CPP_LAST_EQ && b == CPP_EQ)
|
||||
return (enum cpp_ttype) ((int) a + ((int) CPP_EQ_EQ - (int) CPP_EQ));
|
||||
|
||||
switch (a)
|
||||
{
|
||||
case CPP_GREATER:
|
||||
if (b == a) return CPP_RSHIFT;
|
||||
if (b == CPP_QUERY && cxx) return CPP_MAX;
|
||||
if (b == CPP_GREATER_EQ) return CPP_RSHIFT_EQ;
|
||||
break;
|
||||
case CPP_LESS:
|
||||
if (b == a) return CPP_LSHIFT;
|
||||
if (b == CPP_QUERY && cxx) return CPP_MIN;
|
||||
if (b == CPP_LESS_EQ) return CPP_LSHIFT_EQ;
|
||||
if (CPP_OPTION (pfile, digraphs))
|
||||
{
|
||||
if (b == CPP_COLON)
|
||||
{*digraph = 1; return CPP_OPEN_SQUARE;} /* <: digraph */
|
||||
if (b == CPP_MOD)
|
||||
{*digraph = 1; return CPP_OPEN_BRACE;} /* <% digraph */
|
||||
}
|
||||
break;
|
||||
|
||||
case CPP_PLUS: if (b == a) return CPP_PLUS_PLUS; break;
|
||||
case CPP_AND: if (b == a) return CPP_AND_AND; break;
|
||||
case CPP_OR: if (b == a) return CPP_OR_OR; break;
|
||||
|
||||
case CPP_MINUS:
|
||||
if (b == a) return CPP_MINUS_MINUS;
|
||||
if (b == CPP_GREATER) return CPP_DEREF;
|
||||
break;
|
||||
case CPP_COLON:
|
||||
if (b == a && cxx) return CPP_SCOPE;
|
||||
if (b == CPP_GREATER && CPP_OPTION (pfile, digraphs))
|
||||
{*digraph = 1; return CPP_CLOSE_SQUARE;} /* :> digraph */
|
||||
break;
|
||||
|
||||
case CPP_MOD:
|
||||
if (CPP_OPTION (pfile, digraphs))
|
||||
{
|
||||
if (b == CPP_GREATER)
|
||||
{*digraph = 1; return CPP_CLOSE_BRACE;} /* %> digraph */
|
||||
if (b == CPP_COLON)
|
||||
{*digraph = 1; return CPP_HASH;} /* %: digraph */
|
||||
}
|
||||
break;
|
||||
case CPP_DEREF:
|
||||
if (b == CPP_MULT && cxx) return CPP_DEREF_STAR;
|
||||
break;
|
||||
case CPP_DOT:
|
||||
if (b == CPP_MULT && cxx) return CPP_DOT_STAR;
|
||||
if (b == CPP_NUMBER) return CPP_NUMBER;
|
||||
break;
|
||||
|
||||
case CPP_HASH:
|
||||
if (b == a && (token1->flags & DIGRAPH) == (token2->flags & DIGRAPH))
|
||||
/* %:%: digraph */
|
||||
{*digraph = (token1->flags & DIGRAPH); return CPP_PASTE;}
|
||||
break;
|
||||
|
||||
case CPP_NAME:
|
||||
if (b == CPP_NAME) return CPP_NAME;
|
||||
if (b == CPP_NUMBER
|
||||
&& name_p (pfile, &token2->val.str)) return CPP_NAME;
|
||||
if (b == CPP_CHAR
|
||||
&& token1->val.node == pfile->spec_nodes.n_L) return CPP_WCHAR;
|
||||
if (b == CPP_STRING
|
||||
&& token1->val.node == pfile->spec_nodes.n_L) return CPP_WSTRING;
|
||||
break;
|
||||
|
||||
case CPP_NUMBER:
|
||||
if (b == CPP_NUMBER) return CPP_NUMBER;
|
||||
if (b == CPP_NAME) return CPP_NUMBER;
|
||||
if (b == CPP_DOT) return CPP_NUMBER;
|
||||
/* Numbers cannot have length zero, so this is safe. */
|
||||
if ((b == CPP_PLUS || b == CPP_MINUS)
|
||||
&& VALID_SIGN ('+', token1->val.str.text[token1->val.str.len - 1]))
|
||||
return CPP_NUMBER;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return CPP_EOF;
|
||||
}
|
||||
|
||||
/* Returns nonzero if a space should be inserted to avoid an
|
||||
accidental token paste for output. For simplicity, it is
|
||||
conservative, and occasionally advises a space where one is not
|
||||
@ -2139,7 +2032,8 @@ struct dummy
|
||||
#define DEFAULT_ALIGNMENT (offsetof (struct dummy, u))
|
||||
#define CPP_ALIGN(size, align) (((size) + ((align) - 1)) & ~((align) - 1))
|
||||
|
||||
/* Create a new allocation buffer. */
|
||||
/* Create a new allocation buffer. Place the control block at the end
|
||||
of the buffer, so that buffer overflows will cause immediate chaos. */
|
||||
static _cpp_buff *
|
||||
new_buff (len)
|
||||
unsigned int len;
|
||||
|
@ -496,8 +496,6 @@ extern int cpp_start_read PARAMS ((cpp_reader *, const char *));
|
||||
extern void cpp_finish PARAMS ((cpp_reader *));
|
||||
extern int cpp_avoid_paste PARAMS ((cpp_reader *, const cpp_token *,
|
||||
const cpp_token *));
|
||||
extern enum cpp_ttype cpp_can_paste PARAMS ((cpp_reader *, const cpp_token *,
|
||||
const cpp_token *, int *));
|
||||
extern const cpp_token *cpp_get_token PARAMS ((cpp_reader *));
|
||||
extern const unsigned char *cpp_macro_definition PARAMS ((cpp_reader *,
|
||||
const cpp_hashnode *));
|
||||
|
115
gcc/cppmacro.c
115
gcc/cppmacro.c
@ -74,8 +74,8 @@ static const cpp_token *new_string_token PARAMS ((cpp_reader *, U_CHAR *,
|
||||
static const cpp_token *new_number_token PARAMS ((cpp_reader *, int));
|
||||
static const cpp_token *stringify_arg PARAMS ((cpp_reader *, macro_arg *));
|
||||
static void paste_all_tokens PARAMS ((cpp_reader *, const cpp_token *));
|
||||
static int paste_tokens PARAMS ((cpp_reader *, cpp_token *,
|
||||
const cpp_token *));
|
||||
static bool paste_tokens PARAMS ((cpp_reader *, const cpp_token **,
|
||||
const cpp_token *));
|
||||
static int funlike_invocation_p PARAMS ((cpp_reader *, const cpp_hashnode *));
|
||||
static void replace_args PARAMS ((cpp_reader *, cpp_macro *, macro_arg *));
|
||||
|
||||
@ -330,71 +330,49 @@ stringify_arg (pfile, arg)
|
||||
return new_string_token (pfile, start, total_len);
|
||||
}
|
||||
|
||||
/* Try to paste two tokens. On success, the LHS becomes the pasted
|
||||
token, and 0 is returned. For failure, we update the flags of the
|
||||
RHS appropriately and return non-zero. */
|
||||
static int
|
||||
paste_tokens (pfile, lhs, rhs)
|
||||
/* Try to paste two tokens. On success, return non-zero. In any
|
||||
case, PLHS is updated to point to the pasted token, which is
|
||||
guaranteed to not have the PASTE_LEFT flag set. */
|
||||
static bool
|
||||
paste_tokens (pfile, plhs, rhs)
|
||||
cpp_reader *pfile;
|
||||
cpp_token *lhs;
|
||||
const cpp_token *rhs;
|
||||
const cpp_token **plhs, *rhs;
|
||||
{
|
||||
unsigned char flags = 0;
|
||||
int digraph = 0;
|
||||
enum cpp_ttype type;
|
||||
unsigned char *buf, *end;
|
||||
const cpp_token *lhs;
|
||||
unsigned int len;
|
||||
bool valid;
|
||||
|
||||
type = cpp_can_paste (pfile, lhs, rhs, &digraph);
|
||||
|
||||
if (type == CPP_EOF)
|
||||
{
|
||||
/* Mandatory warning for all apart from assembler. */
|
||||
if (CPP_OPTION (pfile, lang) != CLK_ASM)
|
||||
cpp_warning (pfile,
|
||||
"pasting \"%s\" and \"%s\" does not give a valid preprocessing token",
|
||||
cpp_token_as_text (pfile, lhs),
|
||||
cpp_token_as_text (pfile, rhs));
|
||||
return 1;
|
||||
}
|
||||
lhs = *plhs;
|
||||
len = cpp_token_len (lhs) + cpp_token_len (rhs) + 1;
|
||||
buf = (unsigned char *) alloca (len);
|
||||
end = cpp_spell_token (pfile, lhs, buf);
|
||||
|
||||
if (digraph)
|
||||
flags |= DIGRAPH;
|
||||
/* Avoid comment headers, since they are still processed in stage 3.
|
||||
It is simpler to insert a space here, rather than modifying the
|
||||
lexer to ignore comments in some circumstances. Simply returning
|
||||
false doesn't work, since we want to clear the PASTE_LEFT flag. */
|
||||
if (lhs->type == CPP_DIV
|
||||
&& (rhs->type == CPP_MULT || rhs->type == CPP_DIV))
|
||||
*end++ = ' ';
|
||||
end = cpp_spell_token (pfile, rhs, end);
|
||||
|
||||
/* Identifiers and numbers need spellings to be pasted. */
|
||||
if (type == CPP_NAME || type == CPP_NUMBER)
|
||||
{
|
||||
unsigned int total_len = cpp_token_len (lhs) + cpp_token_len (rhs);
|
||||
unsigned char *result, *end;
|
||||
cpp_push_buffer (pfile, buf, end - buf, /* from_stage3 */ true, 1);
|
||||
|
||||
result = _cpp_pool_alloc (&pfile->ident_pool, total_len + 1);
|
||||
/* Tweak the column number the lexer will report. */
|
||||
pfile->buffer->col_adjust = pfile->cur_token[-1].col - 1;
|
||||
|
||||
/* Paste the spellings and null terminate. */
|
||||
end = cpp_spell_token (pfile, rhs, cpp_spell_token (pfile, lhs, result));
|
||||
*end = '\0';
|
||||
total_len = end - result;
|
||||
/* We don't want a leading # to be interpreted as a directive. */
|
||||
pfile->buffer->saved_flags = 0;
|
||||
|
||||
if (type == CPP_NAME)
|
||||
{
|
||||
lhs->val.node = cpp_lookup (pfile, result, total_len);
|
||||
if (lhs->val.node->flags & NODE_OPERATOR)
|
||||
{
|
||||
flags |= NAMED_OP;
|
||||
lhs->type = lhs->val.node->value.operator;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
lhs->val.str.text = result;
|
||||
lhs->val.str.len = total_len;
|
||||
}
|
||||
}
|
||||
else if (type == CPP_WCHAR || type == CPP_WSTRING)
|
||||
lhs->val.str = rhs->val.str;
|
||||
/* Set pfile->cur_token as required by _cpp_lex_direct. */
|
||||
pfile->cur_token = _cpp_temp_token (pfile);
|
||||
*plhs = _cpp_lex_direct (pfile);
|
||||
valid = (pfile->buffer->cur == pfile->buffer->rlimit
|
||||
&& pfile->buffer->read_ahead == EOF);
|
||||
_cpp_pop_buffer (pfile);
|
||||
|
||||
/* Set type and flags after pasting spellings. */
|
||||
lhs->type = type;
|
||||
lhs->flags = flags;
|
||||
|
||||
return 0;
|
||||
return valid;
|
||||
}
|
||||
|
||||
/* Handles an arbitrarily long sequence of ## operators. This
|
||||
@ -407,16 +385,9 @@ paste_all_tokens (pfile, lhs)
|
||||
cpp_reader *pfile;
|
||||
const cpp_token *lhs;
|
||||
{
|
||||
cpp_token *pasted;
|
||||
const cpp_token *rhs;
|
||||
cpp_context *context = pfile->context;
|
||||
|
||||
/* Copy lhs to pasted, but preserve original line and column. */
|
||||
pasted = _cpp_temp_token (pfile);
|
||||
pasted->type = lhs->type;
|
||||
pasted->flags = lhs->flags;
|
||||
pasted->val.str = lhs->val.str;
|
||||
|
||||
do
|
||||
{
|
||||
/* Take the token directly from the current context. We can do
|
||||
@ -432,17 +403,23 @@ paste_all_tokens (pfile, lhs)
|
||||
if (rhs->type == CPP_PADDING)
|
||||
abort ();
|
||||
|
||||
if (paste_tokens (pfile, pasted, rhs))
|
||||
if (!paste_tokens (pfile, &lhs, rhs))
|
||||
{
|
||||
_cpp_backup_tokens (pfile, 1);
|
||||
|
||||
/* Mandatory warning for all apart from assembler. */
|
||||
if (CPP_OPTION (pfile, lang) != CLK_ASM)
|
||||
cpp_warning (pfile,
|
||||
"pasting \"%s\" and \"%s\" does not give a valid preprocessing token",
|
||||
cpp_token_as_text (pfile, lhs),
|
||||
cpp_token_as_text (pfile, rhs));
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (rhs->flags & PASTE_LEFT);
|
||||
|
||||
/* Clear PASTE_LEFT flag, put the token in its own context. */
|
||||
pasted->flags &= ~PASTE_LEFT;
|
||||
push_token_context (pfile, NULL, pasted, 1);
|
||||
/* Put the resulting token in its own context. */
|
||||
push_token_context (pfile, NULL, lhs, 1);
|
||||
}
|
||||
|
||||
/* Reads and returns the arguments to a function-like macro invocation.
|
||||
|
Loading…
Reference in New Issue
Block a user