Commit 711b8824 by Zack Weinberg

[multiple changes]

2000-02-17  Zack Weinberg  <zack@wolery.cumb.org>

	* cpphash.c: Don't include hashtab.h.  Most macro-handling code
	moved to cppmacro.c.
	(hash_HASHNODE, eq_HASHNODE, _cpp_dump_macro_hash,
	dump_hash_helper): Delete.
	(expand_hash, higher_prime_number, _cpp_lookup_with_hash,
	cpp_forall_identifiers): New. Implement specialized version of
	Vlad's expandable hash table.
	(cpp_lookup): Use new functions.
	(_cpp_init_macros, _cpp_cleanup_macros): Adjust for new
	implementation.
	* cppmacro.c: New file.
	* cppinit.c (dump_macros_helper): New.
	(cpp_finish): Iterate over the identifier table directly.
	* cpplex.c (parse_name): Calculate the hash of the identifier
	while we scan it.  Use _cpp_lookup_with_hash when we can.

	* cpphash.h: Update prototypes.
	(xcnewvec, HASHSTEP): New helper macros.
	* cpplib.h: Update prototypes.
	* Makefile.in (LIBCPP_OBJS): Add cppmacro.o.
	(cppmacro.o): New rule.
	(cpphash.o): Update deps.

	* cppmain.c: Do not set pfile->printer if no_output is on.

2000-02-15  Neil Booth  <neilb@earthling.net>

	* cpplib.c: Change all directive-handler functions to return
	void, not int.
	* cpphash.h: Update typedefs.

From-SVN: r35113
parent 5d8fcdcb
2000-02-17 Zack Weinberg <zack@wolery.cumb.org>
* cpphash.c: Don't include hashtab.h. Most macro-handling code
moved to cppmacro.c.
(hash_HASHNODE, eq_HASHNODE, _cpp_dump_macro_hash,
dump_hash_helper): Delete.
(expand_hash, higher_prime_number, _cpp_lookup_with_hash,
cpp_forall_identifiers): New. Implement specialized version of
Vlad's expandable hash table.
(cpp_lookup): Use new functions.
(_cpp_init_macros, _cpp_cleanup_macros): Adjust for new
implementation.
* cppmacro.c: New file.
* cppinit.c (dump_macros_helper): New.
(cpp_finish): Iterate over the identifier table directly.
* cpplex.c (parse_name): Calculate the hash of the identifier
while we scan it. Use _cpp_lookup_with_hash when we can.
* cpphash.h: Update prototypes.
(xcnewvec, HASHSTEP): New helper macros.
* cpplib.h: Update prototypes.
* Makefile.in (LIBCPP_OBJS): Add cppmacro.o.
(cppmacro.o): New rule.
(cpphash.o): Update deps.
* cppmain.c: Do not set pfile->printer if no_output is on.
2000-02-15 Neil Booth <neilb@earthling.net>
* cpplib.c: Change all directive-handler functions to return
void, not int.
* cpphash.h: Update typedefs.
2000-07-17 Geoffrey Keating <geoffk@cygnus.com>
* configure: Regenerate.
......
......@@ -1782,9 +1782,9 @@ PREPROCESSOR_DEFINES = \
-DCROSS_INCLUDE_DIR=\"$(gcc_tooldir)/sys-include\" \
-DTOOL_INCLUDE_DIR=\"$(gcc_tooldir)/include\"
LIBCPP_OBJS = cpplib.o cpphash.o cpperror.o cppexp.o cppfiles.o \
cppinit.o cppulp.o cpplex.o cppdefault.o mkdeps.o \
prefix.o version.o mbchar.o @extra_cpp_objs@
LIBCPP_OBJS = cpplib.o cpplex.o cppmacro.o cppexp.o cppfiles.o \
cpphash.o cpperror.o cppinit.o cppulp.o cppdefault.o \
mkdeps.o prefix.o version.o mbchar.o @extra_cpp_objs@
LIBCPP_DEPS = cpplib.h cpphash.h intl.h system.h
......@@ -1806,8 +1806,9 @@ cppulp.o: cppulp.c $(CONFIG_H) system.h output.h
cpperror.o: cpperror.c $(CONFIG_H) $(LIBCPP_DEPS)
cppexp.o: cppexp.c $(CONFIG_H) $(LIBCPP_DEPS)
cpplex.o: cpplex.c $(CONFIG_H) $(LIBCPP_DEPS)
cppmacro.o: cppmacro.c $(CONFIG_H) $(LIBCPP_DEPS)
cpplib.o: cpplib.c $(CONFIG_H) $(LIBCPP_DEPS) $(OBSTACK_H)
cpphash.o: cpphash.c $(CONFIG_H) $(LIBCPP_DEPS) $(OBSTACK_H) $(HASHTAB_H)
cpphash.o: cpphash.c $(CONFIG_H) $(LIBCPP_DEPS) $(OBSTACK_H)
cppfiles.o: cppfiles.c $(CONFIG_H) $(LIBCPP_DEPS) $(SPLAY_TREE_H) mkdeps.h
cppinit.o: cppinit.c $(CONFIG_H) $(LIBCPP_DEPS) cppdefault.h \
mkdeps.h prefix.h output.h version.h
......
......@@ -72,7 +72,7 @@ struct answer
#define COMMENTS (1 << 3)
/* Defines one #-directive, including how to handle it. */
typedef int (*directive_handler) PARAMS ((cpp_reader *));
typedef void (*directive_handler) PARAMS ((cpp_reader *));
struct directive
{
directive_handler handler; /* Function to handle directive. */
......@@ -202,18 +202,24 @@ extern unsigned char _cpp_IStable[256];
#define CPP_WTRADITIONAL(PF) \
(CPP_OPTION (PF, warn_traditional) && !CPP_IN_SYSTEM_HEADER (PF))
/* Hash step. The hash calculation is duplicated in cpp_lookup and
parse_name. */
#define HASHSTEP(r, str) ((r) * 67 + (*str - 113));
/* Flags for _cpp_init_toklist. */
#define DUMMY_TOKEN 0
#define NO_DUMMY_TOKEN 1
/* In cpphash.c */
extern unsigned int _cpp_calc_hash PARAMS ((const U_CHAR *, size_t));
/* In cppmacro.c */
extern void _cpp_free_definition PARAMS ((cpp_hashnode *));
extern int _cpp_create_definition PARAMS ((cpp_reader *, cpp_hashnode *));
extern void _cpp_dump_definition PARAMS ((cpp_reader *, cpp_hashnode *));
/* In cpphash.c */
extern void _cpp_init_macros PARAMS ((cpp_reader *));
extern void _cpp_cleanup_macros PARAMS ((cpp_reader *));
extern void _cpp_dump_macro_hash PARAMS ((cpp_reader *));
extern cpp_hashnode *_cpp_lookup_with_hash PARAMS ((cpp_reader*, const U_CHAR *,
size_t, unsigned int));
/* In cppfiles.c */
extern void _cpp_simplify_pathname PARAMS ((char *));
......@@ -278,6 +284,7 @@ extern void _cpp_cleanup_stacks PARAMS ((cpp_reader *));
/* Utility routines and macros. */
#define xnew(T) (T *) xmalloc (sizeof(T))
#define xnewvec(T, N) (T *) xmalloc (sizeof(T) * (N))
#define xcnewvec(T, N) (T *) xcalloc (N, sizeof(T))
#define xobnew(O, T) (T *) obstack_alloc (O, sizeof(T))
/* These are inline functions instead of macros so we can get type
......
......@@ -114,6 +114,7 @@ static int opt_comp PARAMS ((const void *, const void *));
static void sort_options PARAMS ((void));
#endif
static int parse_option PARAMS ((const char *));
static int dump_macros_helper PARAMS ((cpp_reader *, cpp_hashnode *));
/* Fourth argument to append_include_chain: chain to use */
enum { QUOTE = 0, BRACKET, SYSTEM, AFTER };
......@@ -891,6 +892,18 @@ cpp_start_read (pfile, print, fname)
return 1;
}
/* Dump out the hash table. */
static int
dump_macros_helper (pfile, hp)
cpp_reader *pfile;
cpp_hashnode *hp;
{
if (hp->type == T_MACRO)
_cpp_dump_definition (pfile, hp);
return 1;
}
/* This is called at the end of preprocessing. It pops the
last buffer and writes dependency output. It should also
clear macro definitions, such that you could call cpp_start_read
......@@ -934,7 +947,7 @@ cpp_finish (pfile, print)
}
if (CPP_OPTION (pfile, dump_macros) == dump_only)
_cpp_dump_macro_hash (pfile);
cpp_forall_identifiers (pfile, dump_macros_helper);
/* Flush any pending output. */
if (print)
......
......@@ -1070,16 +1070,21 @@ skip_whitespace (pfile, in_directive)
}
}
/* Parse (append) an identifier. */
/* Parse (append) an identifier. Calculates the hash value of the
token while parsing, for performance. The algorithm *must* match
cpp_lookup(). */
static const U_CHAR *
parse_name (pfile, tok, cur, rlimit)
cpp_reader *pfile;
cpp_token *tok;
const U_CHAR *cur, *rlimit;
{
const U_CHAR *name = cur;
const U_CHAR *name;
unsigned int len;
unsigned int r;
name = cur;
r = 0;
while (cur < rlimit)
{
if (! is_idchar (*cur))
......@@ -1092,21 +1097,23 @@ parse_name (pfile, tok, cur, rlimit)
CPP_BUFFER (pfile)->cur = cur;
cpp_pedwarn (pfile, "'$' character in identifier");
}
r = HASHSTEP (r, cur);
cur++;
}
len = cur - name;
if (tok->val.node)
if (tok->val.node == 0)
tok->val.node = _cpp_lookup_with_hash (pfile, name, len, r);
else
{
unsigned int oldlen = tok->val.node->length;
U_CHAR *newname = alloca (oldlen + len);
memcpy (newname, tok->val.node->name, oldlen);
memcpy (newname + oldlen, name, len);
len += oldlen;
name = newname;
tok->val.node = cpp_lookup (pfile, newname, len + oldlen);
}
tok->val.node = cpp_lookup (pfile, name, len);
return cur;
}
......
......@@ -113,7 +113,7 @@ SCCS_ENTRY /* 0 SVR2? */
pointers to functions returning void. */
/* Don't invoke CONCAT2 with any whitespace or K&R cc will fail. */
#define D(name, t, o, f) static int CONCAT2(do_,name) PARAMS ((cpp_reader *));
#define D(name, t, o, f) static void CONCAT2(do_,name) PARAMS ((cpp_reader *));
DIRECTIVE_TABLE
#undef D
......@@ -272,7 +272,7 @@ get_define_node (pfile)
}
/* Process a #define command. */
static int
static void
do_define (pfile)
cpp_reader *pfile;
{
......@@ -287,11 +287,10 @@ do_define (pfile)
else if (CPP_OPTION (pfile, dump_macros) == dump_names)
dump_macro_name (pfile, node);
}
return 0;
}
/* Remove the definition of a symbol from the symbol table. */
static int
static void
do_undef (pfile)
cpp_reader *pfile;
{
......@@ -317,8 +316,6 @@ do_undef (pfile)
_cpp_free_definition (node);
node->type = T_VOID;
}
return 0;
}
......@@ -360,7 +357,7 @@ parse_include (pfile, dir, trail, strp, lenp, abp)
return 0;
}
static int
static void
do_include (pfile)
cpp_reader *pfile;
{
......@@ -369,15 +366,14 @@ do_include (pfile)
int ab;
if (parse_include (pfile, dtable[T_INCLUDE].name, 0, &str, &len, &ab))
return 0;
return;
_cpp_execute_include (pfile, str, len, 0, 0, ab);
if (CPP_OPTION (pfile, dump_includes))
pass_thru_directive (pfile);
return 0;
}
static int
static void
do_import (pfile)
cpp_reader *pfile;
{
......@@ -394,15 +390,14 @@ do_import (pfile)
}
if (parse_include (pfile, dtable[T_IMPORT].name, 0, &str, &len, &ab))
return 0;
return;
_cpp_execute_include (pfile, str, len, 1, 0, ab);
if (CPP_OPTION (pfile, dump_includes))
pass_thru_directive (pfile);
return 0;
}
static int
static void
do_include_next (pfile)
cpp_reader *pfile;
{
......@@ -412,7 +407,7 @@ do_include_next (pfile)
int ab;
if (parse_include (pfile, dtable[T_INCLUDE_NEXT].name, 0, &str, &len, &ab))
return 0;
return;
/* For #include_next, skip in the search path past the dir in which
the current file was found. If this is the last directory in the
......@@ -426,7 +421,7 @@ do_include_next (pfile)
{
search_start = CPP_BUFFER (pfile)->inc->foundhere->next;
if (!search_start)
return 0;
return;
}
}
else
......@@ -435,8 +430,6 @@ do_include_next (pfile)
_cpp_execute_include (pfile, str, len, 0, search_start, ab);
if (CPP_OPTION (pfile, dump_includes))
pass_thru_directive (pfile);
return 0;
}
/* Subroutine of do_line. Read next token from PFILE without adding it to
......@@ -494,7 +487,7 @@ strtoul_for_line (str, len, nump)
Note that the filename string (if any) is treated as if it were an
include filename. That means no escape handling. */
static int
static void
do_line (pfile)
cpp_reader *pfile;
{
......@@ -552,7 +545,7 @@ do_line (pfile)
}
if (read_line_number (pfile, &action_number) == 0)
return 0;
return;
if (CPP_PEDANTIC (pfile))
cpp_pedwarn (pfile, "garbage at end of #line");
......@@ -582,10 +575,9 @@ do_line (pfile)
cpp_make_system_header (pfile, ip, 2);
read_line_number (pfile, &action_number);
}
return 0;
done:
return 0;
return;
}
/*
......@@ -594,7 +586,7 @@ do_line (pfile)
* (We use error because it prints the filename & line#.)
*/
static int
static void
do_error (pfile)
cpp_reader *pfile;
{
......@@ -605,8 +597,6 @@ do_error (pfile)
limit = pfile->limit;
pfile->limit = text;
cpp_error (pfile, "%.*s", (int)(limit - text), text);
return 0;
}
/*
......@@ -614,7 +604,7 @@ do_error (pfile)
* Use the text of the line in the warning message, then continue.
*/
static int
static void
do_warning (pfile)
cpp_reader *pfile;
{
......@@ -625,12 +615,11 @@ do_warning (pfile)
limit = pfile->limit;
pfile->limit = text;
cpp_warning (pfile, "%.*s", (int)(limit - text), text);
return 0;
}
/* Report program identification. */
static int
static void
do_ident (pfile)
cpp_reader *pfile;
{
......@@ -641,11 +630,10 @@ do_ident (pfile)
{
/* Good - ship it. */
pass_thru_directive (pfile);
return 0;
return;
}
cpp_error (pfile, "invalid #ident");
return 0;
}
/* Pragmata handling. We handle some of these, and pass the rest on
......@@ -708,7 +696,7 @@ static int pragma_dispatch (pfile, table, node)
return 0;
}
static int
static void
do_pragma (pfile)
cpp_reader *pfile;
{
......@@ -717,17 +705,16 @@ do_pragma (pfile)
tok = _cpp_get_token (pfile);
if (tok->type == CPP_EOF)
return 0;
return;
else if (tok->type != CPP_NAME)
{
cpp_error (pfile, "malformed #pragma directive");
return 0;
return;
}
pop = pragma_dispatch (pfile, top_pragmas, tok->val.node);
if (!pop)
pass_thru_directive (pfile);
return 0;
}
static int
......@@ -900,11 +887,10 @@ do_pragma_dependency (pfile)
/* Just ignore #sccs, on systems where we define it at all. */
#ifdef SCCS_DIRECTIVE
static int
static void
do_sccs (pfile)
cpp_reader *pfile ATTRIBUTE_UNUSED;
{
return 0;
}
#endif
......@@ -991,7 +977,7 @@ parse_ifdef (pfile, name)
/* #ifdef is dead simple. */
static int
static void
do_ifdef (pfile)
cpp_reader *pfile;
{
......@@ -1001,13 +987,12 @@ do_ifdef (pfile)
node = parse_ifdef (pfile, dtable[T_IFDEF].name);
push_conditional (pfile, !(node && node->type != T_VOID), T_IFDEF, 0);
return 0;
}
/* #ifndef is a tad more complex, because we need to check for a
no-reinclusion wrapper. */
static int
static void
do_ifndef (pfile)
cpp_reader *pfile;
{
......@@ -1022,13 +1007,12 @@ do_ifndef (pfile)
push_conditional (pfile, node && node->type != T_VOID,
T_IFNDEF, start_of_file ? node : 0);
return 0;
}
/* #if is straightforward; just call _cpp_parse_expr, then conditional_skip.
Also, check for a reinclude preventer of the form #if !defined (MACRO). */
static int
static void
do_if (pfile)
cpp_reader *pfile;
{
......@@ -1042,14 +1026,13 @@ do_if (pfile)
value = _cpp_parse_expr (pfile);
}
push_conditional (pfile, value == 0, T_IF, cmacro);
return 0;
}
/* #else flips pfile->skipping and continues without changing
if_stack; this is so that the error message for missing #endif's
etc. will point to the original #if. */
static int
static void
do_else (pfile)
cpp_reader *pfile;
{
......@@ -1059,7 +1042,7 @@ do_else (pfile)
if (ifs == NULL)
{
cpp_error (pfile, "#else without #if");
return 0;
return;
}
if (ifs->type == T_ELSE)
{
......@@ -1079,7 +1062,6 @@ do_else (pfile)
if (pfile->skipping < 2)
pfile->skipping = ! pfile->skipping;
}
return 0;
}
/*
......@@ -1087,7 +1069,7 @@ do_else (pfile)
* see the comment above do_else.
*/
static int
static void
do_elif (pfile)
cpp_reader *pfile;
{
......@@ -1096,7 +1078,7 @@ do_elif (pfile)
if (ifs == NULL)
{
cpp_error (pfile, "#elif without #if");
return 0;
return;
}
if (ifs->type == T_ELSE)
{
......@@ -1107,21 +1089,20 @@ do_elif (pfile)
ifs->type = T_ELIF;
if (ifs->was_skipping)
return 0; /* Don't evaluate a nested #if */
return; /* Don't evaluate a nested #if */
if (pfile->skipping != 1)
{
pfile->skipping = 2; /* one block succeeded, so don't do any others */
return 0;
return;
}
pfile->skipping = ! _cpp_parse_expr (pfile);
return 0;
}
/* #endif pops the if stack and resets pfile->skipping. */
static int
static void
do_endif (pfile)
cpp_reader *pfile;
{
......@@ -1138,7 +1119,6 @@ do_endif (pfile)
pfile->potential_control_macro = ifs->cmacro;
obstack_free (pfile->buffer_ob, ifs);
}
return 0;
}
......@@ -1332,7 +1312,7 @@ _cpp_find_answer (node, candidate)
#define WARNING(msgid) do { cpp_warning(pfile, msgid); goto error; } while (0)
#define ERROR(msgid) do { cpp_error(pfile, msgid); goto error; } while (0)
#define ICE(msgid) do { cpp_ice(pfile, msgid); goto error; } while (0)
static int
static void
do_assert (pfile)
cpp_reader *pfile;
{
......@@ -1355,16 +1335,15 @@ do_assert (pfile)
node->type = T_ASSERTION;
node->value.answers = new_answer;
}
return 0;
return;
err:
cpp_warning (pfile, "\"%.*s\" re-asserted",
node->length - 1, node->name + 1);
FREE_ANSWER (new_answer);
return 0;
}
static int
static void
do_unassert (pfile)
cpp_reader *pfile;
{
......@@ -1404,7 +1383,6 @@ do_unassert (pfile)
if (answer)
FREE_ANSWER (answer);
}
return 0;
}
/* These are for -D, -U, -A. */
......
......@@ -653,6 +653,10 @@ extern void cpp_undef PARAMS ((cpp_reader *, const char *));
extern void cpp_unassert PARAMS ((cpp_reader *, const char *));
extern void cpp_free_token_list PARAMS ((cpp_toklist *));
extern cpp_buffer *cpp_push_buffer PARAMS ((cpp_reader *,
const unsigned char *, long));
extern cpp_buffer *cpp_pop_buffer PARAMS ((cpp_reader *));
extern int cpp_defined PARAMS ((cpp_reader *, const unsigned char *, int));
/* N.B. The error-message-printer prototypes have not been nicely
formatted because exgettext needs to see 'msgid' on the same line
......@@ -680,8 +684,8 @@ extern void cpp_pedwarn_with_line PARAMS ((cpp_reader *, int, int, const char *m
ATTRIBUTE_PRINTF_4;
extern void cpp_pedwarn_with_file_and_line PARAMS ((cpp_reader *, const char *, int, int, const char *msgid, ...))
ATTRIBUTE_PRINTF_5;
extern void cpp_error_from_errno PARAMS ((cpp_reader *, const char *));
extern void cpp_notice_from_errno PARAMS ((cpp_reader *, const char *));
extern void cpp_error_from_errno PARAMS ((cpp_reader *, const char *));
extern void cpp_notice_from_errno PARAMS ((cpp_reader *, const char *));
/* In cpplex.c */
extern cpp_buffer *cpp_push_buffer PARAMS ((cpp_reader *,
......@@ -694,16 +698,16 @@ extern int cpp_ideq PARAMS ((const cpp_token *,
const char *));
/* In cpphash.c */
extern int cpp_defined PARAMS ((cpp_reader *,
const unsigned char *, int));
extern cpp_hashnode *cpp_lookup PARAMS ((cpp_reader *,
const unsigned char *, int));
extern cpp_hashnode *cpp_lookup PARAMS ((cpp_reader *,
const unsigned char *, size_t));
extern void cpp_forall_identifiers PARAMS ((cpp_reader *,
int (*) PARAMS ((cpp_reader *,
cpp_hashnode *))));
/* In cppfiles.c */
extern int cpp_included PARAMS ((cpp_reader *, const char *));
extern int cpp_read_file PARAMS ((cpp_reader *, const char *));
extern void cpp_make_system_header PARAMS ((cpp_reader *,
cpp_buffer *, int));
extern int cpp_included PARAMS ((cpp_reader *, const char *));
extern int cpp_read_file PARAMS ((cpp_reader *, const char *));
extern void cpp_make_system_header PARAMS ((cpp_reader *, cpp_buffer *, int));
#ifdef __cplusplus
}
......
This diff is collapsed. Click to expand it.
......@@ -68,7 +68,8 @@ main (argc, argv)
print = cpp_printer_init (pfile, &parse_out);
if (! print)
return (FATAL_EXIT_CODE);
pfile->printer = print;
if (! CPP_OPTION (pfile, no_output))
pfile->printer = print;
if (! cpp_start_read (pfile, print, CPP_OPTION (pfile, in_fname)))
return (FATAL_EXIT_CODE);
......
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