cpphash.h (struct definition): Move file, line, col members...

* cpphash.h (struct definition): Move file, line, col members...
	(struct hashnode): ... here.  Also add 'disabled' flag.
	(enum node_type): Add T_VOID, T_XCONST, T_FMACRO, and
	T_IDENTITY.  Remove T_DISABLED.
	Update prototypes.

	* cpphash.c (_cpp_dump_definition): Split out dump_DEFINITION.
	(collect_expansion): Split into collect_objlike_expansion and
	collect_funlike_expansion.
	(_cpp_macroexpand): Split out scan_arguments, stringify, and
	funlike_macroexpand.
	(_cpp_compare_defs): Rename compare_defs, make static.
	(_cpp_make_hashnode): Initialize hp->disabled.
	(macro_cleanup): Adjust for new token types.  Clear
	m->disabled.
	(_cpp_create_definition): Move code here to determine what
	sort of macro it is, and code to check for redefinitions, from
	do_define.  Implement a few simple cases without creating a
	full DEFINITION.
	(_cpp_macroexpand, special_symbol, _cpp_dump_definition):
	Handle the simple cases.
	(push_macro_expansion): Set buf->has_escapes and hp->disabled
	here.

	* cppinit.c (builtin_array): Change MCONST to XCONST
	everywhere.
	* cpplex.c (maybe_macroexpand): Handle IDENTITY macros here;
	fix check for disabled and function-like macros.
	* cpplib.c (do_define): Move most logic to
	_cpp_create_definition.
	(do_undef): Handle new special token types.

From-SVN: r33355
This commit is contained in:
Zack Weinberg 2000-04-23 17:03:31 +00:00
parent 3c8c10b8c6
commit d9e0bd53b2
6 changed files with 830 additions and 646 deletions

View File

@ -1,3 +1,37 @@
2000-04-23 Zack Weinberg <zack@wolery.cumb.org>
* cpphash.h (struct definition): Move file, line, col members...
(struct hashnode): ... here. Also add 'disabled' flag.
(enum node_type): Add T_VOID, T_XCONST, T_FMACRO, and
T_IDENTITY. Remove T_DISABLED.
Update prototypes.
* cpphash.c (_cpp_dump_definition): Split out dump_DEFINITION.
(collect_expansion): Split into collect_objlike_expansion and
collect_funlike_expansion.
(_cpp_macroexpand): Split out scan_arguments, stringify, and
funlike_macroexpand.
(_cpp_compare_defs): Rename compare_defs, make static.
(_cpp_make_hashnode): Initialize hp->disabled.
(macro_cleanup): Adjust for new token types. Clear
m->disabled.
(_cpp_create_definition): Move code here to determine what
sort of macro it is, and code to check for redefinitions, from
do_define. Implement a few simple cases without creating a
full DEFINITION.
(_cpp_macroexpand, special_symbol, _cpp_dump_definition):
Handle the simple cases.
(push_macro_expansion): Set buf->has_escapes and hp->disabled
here.
* cppinit.c (builtin_array): Change MCONST to XCONST
everywhere.
* cpplex.c (maybe_macroexpand): Handle IDENTITY macros here;
fix check for disabled and function-like macros.
* cpplib.c (do_define): Move most logic to
_cpp_create_definition.
(do_undef): Handle new special token types.
Sun Apr 23 14:27:44 MET DST 2000 Jan Hubicka <jh@suse.cz>
* loop.c (maybe_eliminate_biv_1): Use GET_CODE (x) == CONST_INT instead
@ -53,31 +87,31 @@ Sat Apr 22 22:35:38 MET DST 2000 Jan Hubicka <jh@suse.cz>
* Makefile.in (diagnostic.o): Depends on diagnostic.h
* diagnostic.c: Tweak. Rationalize the output logic. Adjust
* diagnostic.c: Tweak. Rationalize the output logic. Adjust
various function prototypes.
(diagnostic.h): #include.
(struct output_buffer): Move into diagnostic.h.
(get_output_prefix): Rename to output_get_prefix. Export.
(init_output_buffer): Export. Break out. Ajust intialization.
(output_space_left, output_append): Export.
(output_newline): Rename to output_add_newline. Export.
(diagnostic.h): #include.
(struct output_buffer): Move into diagnostic.h.
(get_output_prefix): Rename to output_get_prefix. Export.
(init_output_buffer): Export. Break out. Ajust intialization.
(output_space_left, output_append): Export.
(output_newline): Rename to output_add_newline. Export.
(output_clear): Nullify additional output_buffer fields.
(output_puts): Rename to output_add_string. Export.
(dump_output): Rename to output_flush_on. Export.
(build_location_prefix): Constify return-type.
(emit_output_prefix): Rename to output_emit_prefix. Export.
(set_real_maximum_length): New function.
(output_set_maximum_length): Ditto
(output_clear): Ditto.
(output_add_character): Ditto.
(output_add_integer): Ditto.
(output_add_space): Ditto.
(output_format): Ditto.
(output_printf): Adjust buffer initialization.
(vline_wrapper_message_with_location): Ditto.
(v_message_with_decl): Ditto. Adjust call to output_puts
(output_puts): Rename to output_add_string. Export.
(dump_output): Rename to output_flush_on. Export.
(build_location_prefix): Constify return-type.
(emit_output_prefix): Rename to output_emit_prefix. Export.
(set_real_maximum_length): New function.
(output_set_maximum_length): Ditto
(output_clear): Ditto.
(output_add_character): Ditto.
(output_add_integer): Ditto.
(output_add_space): Ditto.
(output_format): Ditto.
(output_printf): Adjust buffer initialization.
(vline_wrapper_message_with_location): Ditto.
(v_message_with_decl): Ditto. Adjust call to output_puts
and get_output_prefix.
(default_print_error_function): Adjust buffer intialization.
(default_print_error_function): Adjust buffer intialization.
Sat Apr 22 06:45:04 2000 Richard Kenner <kenner@vlsi1.ultra.nyu.edu>

File diff suppressed because it is too large Load Diff

View File

@ -64,9 +64,6 @@ struct definition
int nargs;
int length; /* length of expansion string */
U_CHAR *expansion;
int line; /* Line number of definition */
int col;
const char *file; /* File of definition */
char rest_args; /* Nonzero if last arg. absorbs the rest */
struct reflist *pattern;
@ -86,6 +83,7 @@ struct definition
/* different flavors of hash nodes */
enum node_type
{
T_VOID = 0, /* no definition yet */
T_SPECLINE, /* `__LINE__' */
T_DATE, /* `__DATE__' */
T_FILE, /* `__FILE__' */
@ -94,10 +92,12 @@ enum node_type
T_TIME, /* `__TIME__' */
T_STDC, /* `__STDC__' */
T_CONST, /* Constant string, used by `__SIZE_TYPE__' etc */
T_MCONST, /* Ditto, but the string is malloced memory */
T_MACRO, /* macro defined by `#define' */
T_DISABLED, /* macro temporarily turned off for rescan */
T_POISON, /* macro defined with `#pragma poison' */
T_XCONST, /* Ditto, but the string is malloced memory */
T_POISON, /* poisoned identifier */
T_MCONST, /* object-like macro defined to a single identifier */
T_MACRO, /* general object-like macro */
T_FMACRO, /* general function-like macro */
T_IDENTITY, /* macro defined to itself */
T_EMPTY /* macro defined to nothing */
};
@ -118,6 +118,11 @@ struct hashnode
unsigned long hash; /* cached hash value */
union hashval value; /* pointer to expansion, or whatever */
enum node_type type; /* type of special token */
int disabled; /* macro turned off for rescan? */
const char *file; /* File, line, column of definition; */
int line;
int col;
};
/* List of directories to look for include files in. */
@ -272,12 +277,9 @@ extern HASHNODE **_cpp_lookup_slot PARAMS ((cpp_reader *,
enum insert_option,
unsigned long *));
extern void _cpp_free_definition PARAMS ((DEFINITION *));
extern DEFINITION *_cpp_create_definition PARAMS ((cpp_reader *,
cpp_toklist *, int));
extern void _cpp_dump_definition PARAMS ((cpp_reader *, const U_CHAR *,
long, DEFINITION *));
extern int _cpp_compare_defs PARAMS ((cpp_reader *, DEFINITION *,
DEFINITION *));
extern int _cpp_create_definition PARAMS ((cpp_reader *,
cpp_toklist *, HASHNODE *));
extern void _cpp_dump_definition PARAMS ((cpp_reader *, HASHNODE *));
extern void _cpp_quote_string PARAMS ((cpp_reader *, const char *));
extern void _cpp_macroexpand PARAMS ((cpp_reader *, HASHNODE *));
extern void _cpp_init_macro_hash PARAMS ((cpp_reader *));

View File

@ -635,7 +635,7 @@ static const struct builtin builtin_array[] =
{ "__LINE__", 0, T_SPECLINE, 0 },
{ "__INCLUDE_LEVEL__", 0, T_INCLUDE_LEVEL, 0 },
{ "__VERSION__", 0, T_MCONST, DUMP|VERS },
{ "__VERSION__", 0, T_XCONST, DUMP|VERS },
{ "__USER_LABEL_PREFIX__", 0, T_CONST, DUMP|ULP },
{ "__STDC__", "1", T_STDC, DUMP },
{ "__REGISTER_PREFIX__", REGISTER_PREFIX, T_CONST, DUMP },

View File

@ -1455,7 +1455,7 @@ maybe_macroexpand (pfile, written)
if (!hp)
return 0;
if (hp->type == T_DISABLED)
if (hp->disabled || hp->type == T_IDENTITY)
{
if (pfile->output_escapes)
{
@ -1479,7 +1479,7 @@ maybe_macroexpand (pfile, written)
}
/* If macro wants an arglist, verify that a '(' follows. */
if (hp->type == T_MACRO && hp->value.defn->nargs >= 0)
if (hp->type == T_FMACRO)
{
int macbuf_whitespace = 0;
int c;

View File

@ -316,10 +316,8 @@ do_define (pfile)
cpp_reader *pfile;
{
HASHNODE **slot;
DEFINITION *def = 0;
unsigned long hash;
int len;
int funlike = 0, empty = 0;
U_CHAR *sym;
cpp_toklist *list = &pfile->directbuf;
@ -350,90 +348,26 @@ do_define (pfile)
goto out;
}
if (list->tokens_used == 2 && list->tokens[1].type == CPP_VSPACE)
empty = 1; /* Empty definition of object-like macro. */
/* If the next character, with no intervening whitespace, is '(',
then this is a function-like macro. Otherwise it is an object-
like macro, and C99 requires whitespace after the name
(6.10.3 para 3). */
else if (!(list->tokens[1].flags & HSPACE_BEFORE))
{
if (list->tokens[1].type == CPP_OPEN_PAREN)
funlike = 1;
else
cpp_pedwarn (pfile,
"The C standard requires whitespace after #define %.*s",
len, sym);
}
if (! empty)
{
def = _cpp_create_definition (pfile, list, funlike);
if (def == 0)
goto out;
}
slot = _cpp_lookup_slot (pfile, sym, len, INSERT, &hash);
if (*slot)
{
int ok;
HASHNODE *hp = *slot;
/* Redefining a macro is ok if the definitions are the same. */
if (hp->type == T_MACRO)
ok = ! empty && ! _cpp_compare_defs (pfile, def, hp->value.defn);
else if (hp->type == T_EMPTY)
ok = empty;
/* Redefining a constant is ok with -D. */
else if (hp->type == T_CONST || hp->type == T_STDC)
ok = ! pfile->done_initializing;
/* Otherwise it's not ok. */
else
ok = 0;
/* Print the warning or error if it's not ok. */
if (! ok)
/* Check for poisoned identifiers now. All other checks
are done in cpphash.c. */
if ((*slot)->type == T_POISON)
{
if (hp->type == T_POISON)
cpp_error (pfile, "redefining poisoned `%.*s'", len, sym);
else
cpp_pedwarn (pfile, "`%.*s' redefined", len, sym);
if (hp->type == T_MACRO && pfile->done_initializing)
{
DEFINITION *d = hp->value.defn;
cpp_pedwarn_with_file_and_line (pfile, d->file, d->line, d->col,
"this is the location of the previous definition");
}
}
if (hp->type != T_POISON)
{
/* Replace the old definition. */
if (hp->type == T_MACRO)
_cpp_free_definition (hp->value.defn);
if (empty)
{
hp->type = T_EMPTY;
hp->value.defn = 0;
}
else
{
hp->type = T_MACRO;
hp->value.defn = def;
}
cpp_error (pfile, "redefining poisoned `%.*s'", len, sym);
goto out;
}
}
else
{
HASHNODE *hp = _cpp_make_hashnode (sym, len, empty ? T_EMPTY : T_MACRO,
hash);
hp->value.defn = def;
*slot = hp;
}
*slot = _cpp_make_hashnode (sym, len, T_VOID, hash);
if (_cpp_create_definition (pfile, list, *slot) == 0)
goto out;
if (CPP_OPTION (pfile, debug_output)
|| CPP_OPTION (pfile, dump_macros) == dump_definitions)
_cpp_dump_definition (pfile, sym, len, def);
_cpp_dump_definition (pfile, *slot);
else if (CPP_OPTION (pfile, dump_macros) == dump_names)
pass_thru_directive (sym, len, pfile, T_DEFINE);
@ -769,7 +703,9 @@ do_undef (pfile)
if (CPP_OPTION (pfile, debug_output))
pass_thru_directive (hp->name, len, pfile, T_UNDEF);
if (hp->type != T_MACRO && hp->type != T_EMPTY)
if (hp->type != T_MACRO && hp->type != T_FMACRO
&& hp->type != T_MCONST
&& hp->type != T_EMPTY && hp->type != T_IDENTITY)
cpp_warning (pfile, "undefining `%s'", hp->name);
htab_clear_slot (pfile->hashtab, (void **)slot);