cpplib: token length tweak.
Neil Booth
neil@daikokuya.co.uk
Thu Apr 24 20:02:00 GMT 2003
Just tightens up reported lengths.
Neil.
* cpplex.c (cpp_token_len): Tighten up.
(cpp_token_as_text): Need extra byte now.
* cpplib.c (glue_header_name): Need extra 2 bytes.
* cppmacro.c (cpp_macro_definition): Need extra byte.
Index: cpplex.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpplex.c,v
retrieving revision 1.230
diff -u -p -r1.230 cpplex.c
--- cpplex.c 23 Apr 2003 22:43:57 -0000 1.230
+++ cpplex.c 24 Apr 2003 20:00:26 -0000
@@ -1094,8 +1094,8 @@ _cpp_lex_direct (pfile)
return result;
}
-/* An upper bound on the number of bytes needed to spell TOKEN,
- including preceding whitespace. */
+/* An upper bound on the number of bytes needed to spell TOKEN.
+ Does not include preceding whitespace. */
unsigned int
cpp_token_len (token)
const cpp_token *token;
@@ -1104,12 +1104,12 @@ cpp_token_len (token)
switch (TOKEN_SPELL (token))
{
- default: len = 0; break;
+ default: len = 4; break;
case SPELL_LITERAL: len = token->val.str.len; break;
case SPELL_IDENT: len = NODE_LEN (token->val.node); break;
}
- /* 1 for whitespace, 4 for comment delimiters. */
- return len + 5;
+
+ return len;
}
/* Write the spelling of a token TOKEN to BUFFER. The buffer must
@@ -1167,8 +1167,8 @@ unsigned char *
cpp_token_as_text (pfile, token)
cpp_reader *pfile;
const cpp_token *token;
-{
- unsigned int len = cpp_token_len (token);
+{
+ unsigned int len = cpp_token_len (token) + 1;
unsigned char *start = _cpp_unaligned_alloc (pfile, len), *end;
end = cpp_spell_token (pfile, token, start);
Index: cpplib.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpplib.c,v
retrieving revision 1.335
diff -u -p -r1.335 cpplib.c
--- cpplib.c 23 Apr 2003 22:43:58 -0000 1.335
+++ cpplib.c 24 Apr 2003 20:00:27 -0000
@@ -594,7 +594,7 @@ glue_header_name (pfile)
break;
}
- len = cpp_token_len (token);
+ len = cpp_token_len (token) + 2; /* Leading space, terminating \0. */
if (total_len + len > capacity)
{
capacity = (capacity + len) * 2;
Index: cppmacro.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppmacro.c,v
retrieving revision 1.132
diff -u -p -r1.132 cppmacro.c
--- cppmacro.c 23 Apr 2003 22:43:58 -0000 1.132
+++ cppmacro.c 24 Apr 2003 20:00:27 -0000
@@ -1715,7 +1715,7 @@ cpp_macro_definition (pfile, node)
if (token->type == CPP_MACRO_ARG)
len += NODE_LEN (macro->params[token->val.arg_no - 1]);
else
- len += cpp_token_len (token); /* Includes room for ' '. */
+ len += cpp_token_len (token) + 1; /* Includes room for ' '. */
if (token->flags & STRINGIFY_ARG)
len++; /* "#" */
if (token->flags & PASTE_LEFT)
More information about the Gcc-patches
mailing list