Commit d15a58c0 by Neil Booth Committed by Neil Booth

cppmacro.c: Don't include intl.h.

	* cppmacro.c: Don't include intl.h.  Update comments.
	(new_number_token): Allocate enough buffer for 64-bit unsigned
	integers; update prototype.
	* cppmain.c: Update comments.

From-SVN: r48518
parent 2fd17409
2002-01-03 Neil Booth <neil@daikokuya.demon.co.uk>
* cppmacro.c: Don't include intl.h. Update comments.
(new_number_token): Allocate enough buffer for 64-bit unsigned
integers; update prototype.
* cppmain.c: Update comments.
2002-01-03 William Cohen <wcohen@redhat.com> 2002-01-03 William Cohen <wcohen@redhat.com>
* function.h (struct function): Add profile. * function.h (struct function): Add profile.
......
...@@ -25,7 +25,6 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ...@@ -25,7 +25,6 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "config.h" #include "config.h"
#include "system.h" #include "system.h"
#include "intl.h" /* for _("<command line>") below. */
#include "cpplib.h" #include "cpplib.h"
#include "cpphash.h" #include "cpphash.h"
...@@ -70,7 +69,7 @@ static unsigned char *quote_string PARAMS ((unsigned char *, ...@@ -70,7 +69,7 @@ static unsigned char *quote_string PARAMS ((unsigned char *,
unsigned int)); unsigned int));
static const cpp_token *new_string_token PARAMS ((cpp_reader *, U_CHAR *, static const cpp_token *new_string_token PARAMS ((cpp_reader *, U_CHAR *,
unsigned int)); unsigned int));
static const cpp_token *new_number_token PARAMS ((cpp_reader *, int)); static const cpp_token *new_number_token PARAMS ((cpp_reader *, unsigned int));
static const cpp_token *stringify_arg PARAMS ((cpp_reader *, macro_arg *)); static const cpp_token *stringify_arg PARAMS ((cpp_reader *, macro_arg *));
static void paste_all_tokens PARAMS ((cpp_reader *, const cpp_token *)); static void paste_all_tokens PARAMS ((cpp_reader *, const cpp_token *));
static bool paste_tokens PARAMS ((cpp_reader *, const cpp_token **, static bool paste_tokens PARAMS ((cpp_reader *, const cpp_token **,
...@@ -112,12 +111,13 @@ new_string_token (pfile, text, len) ...@@ -112,12 +111,13 @@ new_string_token (pfile, text, len)
static const cpp_token * static const cpp_token *
new_number_token (pfile, number) new_number_token (pfile, number)
cpp_reader *pfile; cpp_reader *pfile;
int number; unsigned int number;
{ {
cpp_token *token = _cpp_temp_token (pfile); cpp_token *token = _cpp_temp_token (pfile);
unsigned char *buf = _cpp_unaligned_alloc (pfile, 20); /* 21 bytes holds all NUL-terminated unsigned 64-bit numbers. */
unsigned char *buf = _cpp_unaligned_alloc (pfile, 21);
sprintf ((char *) buf, "%d", number); sprintf ((char *) buf, "%u", number);
token->type = CPP_NUMBER; token->type = CPP_NUMBER;
token->val.str.text = buf; token->val.str.text = buf;
token->val.str.len = ustrlen (buf); token->val.str.len = ustrlen (buf);
...@@ -133,8 +133,8 @@ static const char * const monthnames[] = ...@@ -133,8 +133,8 @@ static const char * const monthnames[] =
/* Handle builtin macros like __FILE__, and push the resulting token /* Handle builtin macros like __FILE__, and push the resulting token
on the context stack. Also handles _Pragma, for which no new token on the context stack. Also handles _Pragma, for which no new token
is created. Returns 1 on success, 0 to return the token to the is created. Returns 1 if it generates a new token context, 0 to
caller. */ return the token to the caller. */
static int static int
builtin_macro (pfile, node) builtin_macro (pfile, node)
cpp_reader *pfile; cpp_reader *pfile;
...@@ -241,8 +241,9 @@ builtin_macro (pfile, node) ...@@ -241,8 +241,9 @@ builtin_macro (pfile, node)
return 1; return 1;
} }
/* Adds backslashes before all backslashes and double quotes appearing /* Copies SRC, of length LEN, to DEST, adding backslashes before all
in strings. Non-printable characters are converted to octal. */ backslashes and double quotes. Non-printable characters are
converted to octal. DEST must be of sufficient size. */
static U_CHAR * static U_CHAR *
quote_string (dest, src, len) quote_string (dest, src, len)
U_CHAR *dest; U_CHAR *dest;
...@@ -273,8 +274,8 @@ quote_string (dest, src, len) ...@@ -273,8 +274,8 @@ quote_string (dest, src, len)
return dest; return dest;
} }
/* Convert a token sequence to a single string token according to the /* Convert a token sequence ARG to a single string token according to
rules of the ISO C #-operator. */ the rules of the ISO C #-operator. */
static const cpp_token * static const cpp_token *
stringify_arg (pfile, arg) stringify_arg (pfile, arg)
cpp_reader *pfile; cpp_reader *pfile;
...@@ -399,11 +400,13 @@ paste_tokens (pfile, plhs, rhs) ...@@ -399,11 +400,13 @@ paste_tokens (pfile, plhs, rhs)
return valid; return valid;
} }
/* Handles an arbitrarily long sequence of ## operators. This /* Handles an arbitrarily long sequence of ## operators, with initial
implementation is left-associative, non-recursive, and finishes a operand LHS. This implementation is left-associative,
paste before handling succeeding ones. If the paste fails, we back non-recursive, and finishes a paste before handling succeeding
up a token to just after the ## operator, with the effect that it ones. If a paste fails, we back up to the RHS of the failing ##
appears in the output stream normally. */ operator before pushing the context containing the result of prior
successful pastes, with the effect that the RHS appears in the
output stream after the pasted LHS normally. */
static void static void
paste_all_tokens (pfile, lhs) paste_all_tokens (pfile, lhs)
cpp_reader *pfile; cpp_reader *pfile;
...@@ -446,9 +449,11 @@ paste_all_tokens (pfile, lhs) ...@@ -446,9 +449,11 @@ paste_all_tokens (pfile, lhs)
push_token_context (pfile, NULL, lhs, 1); push_token_context (pfile, NULL, lhs, 1);
} }
/* Reads and returns the arguments to a function-like macro invocation. /* Reads and returns the arguments to a function-like macro
Assumes the opening parenthesis has been processed. If there is an invocation. Assumes the opening parenthesis has been processed.
error, emits an appropriate diagnostic and returns NULL. */ If there is an error, emits an appropriate diagnostic and returns
NULL. Each argument is terminated by a CPP_EOF token, for the
future benefit of expand_arg(). */
static _cpp_buff * static _cpp_buff *
collect_args (pfile, node) collect_args (pfile, node)
cpp_reader *pfile; cpp_reader *pfile;
...@@ -653,19 +658,19 @@ funlike_invocation_p (pfile, node) ...@@ -653,19 +658,19 @@ funlike_invocation_p (pfile, node)
return NULL; return NULL;
} }
/* Push the context of a macro onto the context stack. TOKEN is the /* Push the context of a macro with hash entry NODE onto the context
macro name. If we can successfully start expanding the macro, stack. If we can successfully expand the macro, we push a context
TOKEN is replaced with the first token of the expansion, and we containing its yet-to-be-rescanned replacement list and return one.
return non-zero. */ Otherwise, we don't push a context and return zero. */
static int static int
enter_macro_context (pfile, node) enter_macro_context (pfile, node)
cpp_reader *pfile; cpp_reader *pfile;
cpp_hashnode *node; cpp_hashnode *node;
{ {
/* Macros invalidate controlling macros. */ /* The presence of a macro invalidates a file's controlling macro. */
pfile->mi_valid = false; pfile->mi_valid = false;
/* Handle macros and the _Pragma operator. */ /* Handle standard macros. */
if (! (node->flags & NODE_BUILTIN)) if (! (node->flags & NODE_BUILTIN))
{ {
cpp_macro *macro = node->value.macro; cpp_macro *macro = node->value.macro;
...@@ -706,12 +711,14 @@ enter_macro_context (pfile, node) ...@@ -706,12 +711,14 @@ enter_macro_context (pfile, node)
return 1; return 1;
} }
/* Handle built-in macros and the _Pragma operator. */
return builtin_macro (pfile, node); return builtin_macro (pfile, node);
} }
/* Take the expansion of a function-like MACRO, replacing parameters /* Replace the parameters in a function-like macro of NODE with the
with the actual arguments. Each argument is macro-expanded before actual ARGS, and place the result in a newly pushed token context.
replacement, unless operated upon by the # or ## operators. */ Expand each argument before replacing, unless it is operated upon
by the # or ## operators. */
static void static void
replace_args (pfile, node, args) replace_args (pfile, node, args)
cpp_reader *pfile; cpp_reader *pfile;
...@@ -864,7 +871,8 @@ padding_token (pfile, source) ...@@ -864,7 +871,8 @@ padding_token (pfile, source)
return result; return result;
} }
/* Move to the next context. Create one if there is none. */ /* Get a new uninitialized context. Create a new one if we cannot
re-use an old one. */
static cpp_context * static cpp_context *
next_context (pfile) next_context (pfile)
cpp_reader *pfile; cpp_reader *pfile;
...@@ -918,6 +926,12 @@ push_token_context (pfile, macro, first, count) ...@@ -918,6 +926,12 @@ push_token_context (pfile, macro, first, count)
context->last.token = first + count; context->last.token = first + count;
} }
/* Expand an argument ARG before replacing parameters in a
function-like macro. This works by pushing a context with the
argument's tokens, and then expanding that into a temporary buffer
as if it were a normal part of the token stream. collect_args()
has terminated the argument's tokens with a CPP_EOF so that we know
when we have fully expanded the argument. */
static void static void
expand_arg (pfile, arg) expand_arg (pfile, arg)
cpp_reader *pfile; cpp_reader *pfile;
...@@ -956,13 +970,15 @@ expand_arg (pfile, arg) ...@@ -956,13 +970,15 @@ expand_arg (pfile, arg)
_cpp_pop_context (pfile); _cpp_pop_context (pfile);
} }
/* Pop the current context off the stack, re-enabling the macro if the
context represented a macro's replacement list. The context
structure is not freed so that we can re-use it later. */
void void
_cpp_pop_context (pfile) _cpp_pop_context (pfile)
cpp_reader *pfile; cpp_reader *pfile;
{ {
cpp_context *context = pfile->context; cpp_context *context = pfile->context;
/* Re-enable a macro when leaving its expansion. */
if (context->macro) if (context->macro)
context->macro->flags &= ~NODE_DISABLED; context->macro->flags &= ~NODE_DISABLED;
...@@ -1040,7 +1056,8 @@ cpp_get_token (pfile) ...@@ -1040,7 +1056,8 @@ cpp_get_token (pfile)
} }
else else
{ {
/* Flag this token as always unexpandable. */ /* Flag this token as always unexpandable. FIXME: move this
to collect_args()?. */
cpp_token *t = _cpp_temp_token (pfile); cpp_token *t = _cpp_temp_token (pfile);
t->type = result->type; t->type = result->type;
t->flags = result->flags | NO_EXPAND; t->flags = result->flags | NO_EXPAND;
...@@ -1149,7 +1166,6 @@ warn_of_redefinition (node, macro2) ...@@ -1149,7 +1166,6 @@ warn_of_redefinition (node, macro2)
} }
/* Free the definition of hashnode H. */ /* Free the definition of hashnode H. */
void void
_cpp_free_definition (h) _cpp_free_definition (h)
cpp_hashnode *h; cpp_hashnode *h;
...@@ -1267,6 +1283,8 @@ alloc_expansion_token (pfile, macro) ...@@ -1267,6 +1283,8 @@ alloc_expansion_token (pfile, macro)
return &((cpp_token *) BUFF_FRONT (pfile->a_buff))[macro->count++]; return &((cpp_token *) BUFF_FRONT (pfile->a_buff))[macro->count++];
} }
/* Lex a token from the expansion of MACRO, but mark parameters as we
find them and warn of traditional stringification. */
static cpp_token * static cpp_token *
lex_expansion_token (pfile, macro) lex_expansion_token (pfile, macro)
cpp_reader *pfile; cpp_reader *pfile;
...@@ -1277,7 +1295,7 @@ lex_expansion_token (pfile, macro) ...@@ -1277,7 +1295,7 @@ lex_expansion_token (pfile, macro)
pfile->cur_token = alloc_expansion_token (pfile, macro); pfile->cur_token = alloc_expansion_token (pfile, macro);
token = _cpp_lex_direct (pfile); token = _cpp_lex_direct (pfile);
/* Is this an argument? */ /* Is this a parameter? */
if (token->type == CPP_NAME && token->val.node->arg_index) if (token->type == CPP_NAME && token->val.node->arg_index)
{ {
token->type = CPP_MACRO_ARG; token->type = CPP_MACRO_ARG;
...@@ -1390,7 +1408,7 @@ _cpp_create_definition (pfile, node) ...@@ -1390,7 +1408,7 @@ _cpp_create_definition (pfile, node)
/* Don't count the CPP_EOF. */ /* Don't count the CPP_EOF. */
macro->count--; macro->count--;
/* Clear whitespace on first token for macro equivalence purposes. */ /* Clear whitespace on first token for warn_of_redefinition(). */
if (macro->count) if (macro->count)
macro->expansion[0].flags &= ~PREV_WHITE; macro->expansion[0].flags &= ~PREV_WHITE;
...@@ -1444,9 +1462,8 @@ _cpp_create_definition (pfile, node) ...@@ -1444,9 +1462,8 @@ _cpp_create_definition (pfile, node)
return ok; return ok;
} }
/* Warn if a token in `string' matches one of the function macro /* Warn if a token in STRING matches one of a function-like MACRO's
arguments in `info'. This function assumes that the macro is a parameters. */
function macro and not an object macro. */
static void static void
check_trad_stringification (pfile, macro, string) check_trad_stringification (pfile, macro, string)
cpp_reader *pfile; cpp_reader *pfile;
...@@ -1493,7 +1510,6 @@ check_trad_stringification (pfile, macro, string) ...@@ -1493,7 +1510,6 @@ check_trad_stringification (pfile, macro, string)
debugging info. e.g. "PASTE(X, Y) X ## Y", or "MACNAME EXPANSION". debugging info. e.g. "PASTE(X, Y) X ## Y", or "MACNAME EXPANSION".
Caller is expected to generate the "#define" bit if needed. The Caller is expected to generate the "#define" bit if needed. The
returned text is temporary, and automatically freed later. */ returned text is temporary, and automatically freed later. */
const unsigned char * const unsigned char *
cpp_macro_definition (pfile, node) cpp_macro_definition (pfile, node)
cpp_reader *pfile; cpp_reader *pfile;
......
...@@ -162,7 +162,7 @@ do_preprocessing (argc, argv) ...@@ -162,7 +162,7 @@ do_preprocessing (argc, argv)
{ {
cpp_finish_options (pfile); cpp_finish_options (pfile);
/* A successful cpp_start_read guarantees that we can call /* A successful cpp_read_main_file guarantees that we can call
cpp_scan_nooutput or cpp_get_token next. */ cpp_scan_nooutput or cpp_get_token next. */
if (options->no_output) if (options->no_output)
cpp_scan_nooutput (pfile); cpp_scan_nooutput (pfile);
...@@ -275,7 +275,6 @@ check_multiline_token (str) ...@@ -275,7 +275,6 @@ check_multiline_token (str)
/* If the token read on logical line LINE needs to be output on a /* If the token read on logical line LINE needs to be output on a
different line to the current one, output the required newlines or different line to the current one, output the required newlines or
a line marker, and return 1. Otherwise return 0. */ a line marker, and return 1. Otherwise return 0. */
static void static void
maybe_print_line (map, line) maybe_print_line (map, line)
const struct line_map *map; const struct line_map *map;
...@@ -330,8 +329,7 @@ print_line (map, line, special_flags) ...@@ -330,8 +329,7 @@ print_line (map, line, special_flags)
} }
/* Called when a line of output is started. TOKEN is the first token /* Called when a line of output is started. TOKEN is the first token
of the line, and may be CPP_EOF. */ of the line, and at end of file will be CPP_EOF. */
static void static void
cb_line_change (pfile, token, parsing_args) cb_line_change (pfile, token, parsing_args)
cpp_reader *pfile ATTRIBUTE_UNUSED; cpp_reader *pfile ATTRIBUTE_UNUSED;
......
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