Commit 40bd4395 by Neil Booth Committed by Neil Booth

tradcpp.c (enum node_type): New hash types T_ASSERT, T_UNASSERT.

        * tradcpp.c (enum node_type): New hash types T_ASSERT, T_UNASSERT.
        (struct directive): Drop 4th argument from handlers.
        (do_define, do_line, do_include, do_undef, do_else, do_elif,
        do_endif): Similarly.
        (do_assert, do_unassert, do_ifdef, do_ifndef): New handlers.
        (do_ifxdef): Update as common handler of do_ifdef and do_ifndef.
        (make_definition, make_undef): Take a const char*.
        (make_assertion): New function.
        (struct directive_table): Update.
        (main): Handle -A command line argument.
        (handle_directive): Drop fourth handler argument.

From-SVN: r37820
parent 77ea49a4
2000-11-28 Neil Booth <neilb@earthling.net>
* tradcpp.c (enum node_type): New hash types T_ASSERT, T_UNASSERT.
(struct directive): Drop 4th argument from handlers.
(do_define, do_line, do_include, do_undef, do_else, do_elif,
do_endif): Similarly.
(do_assert, do_unassert, do_ifdef, do_ifndef): New handlers.
(do_ifxdef): Update as common handler of do_ifdef and do_ifndef.
(make_definition, make_undef): Take a const char*.
(make_assertion): New function.
(struct directive_table): Update.
(main): Handle -A command line argument.
(handle_directive): Drop fourth handler argument.
2000-11-28 Bernd Schmidt <bernds@redhat.co.uk> 2000-11-28 Bernd Schmidt <bernds@redhat.co.uk>
* simplify-rtx.c (cselib_record_sets): Ignore sets whose destination * simplify-rtx.c (cselib_record_sets): Ignore sets whose destination
......
...@@ -215,6 +215,8 @@ enum node_type { ...@@ -215,6 +215,8 @@ enum node_type {
T_UNDEF, /* `#undef' */ T_UNDEF, /* `#undef' */
T_LINE, /* `#line' */ T_LINE, /* `#line' */
T_ENDIF, /* `#endif' */ T_ENDIF, /* `#endif' */
T_ASSERT, /* `#assert' */
T_UNASSERT, /* `#unassert' */
T_SPECLINE, /* special symbol `__LINE__' */ T_SPECLINE, /* special symbol `__LINE__' */
T_DATE, /* `__DATE__' */ T_DATE, /* `__DATE__' */
T_FILE, /* `__FILE__' */ T_FILE, /* `__FILE__' */
...@@ -258,7 +260,7 @@ HASHNODE *hashtab[HASHSIZE]; ...@@ -258,7 +260,7 @@ HASHNODE *hashtab[HASHSIZE];
struct directive { struct directive {
int length; /* Length of name */ int length; /* Length of name */
void (*func) PARAMS ((U_CHAR *, U_CHAR *, FILE_BUF *, struct directive *)); void (*func) PARAMS ((U_CHAR *, U_CHAR *, FILE_BUF *));
/* Function to handle directive */ /* Function to handle directive */
const char *name; /* Name of directive */ const char *name; /* Name of directive */
enum node_type type; /* Code which describes which directive. */ enum node_type type; /* Code which describes which directive. */
...@@ -305,15 +307,19 @@ struct arglist { ...@@ -305,15 +307,19 @@ struct arglist {
/* Function prototypes. */ /* Function prototypes. */
static void do_define PARAMS ((U_CHAR *, U_CHAR *, FILE_BUF *, struct directive *)); static void do_define PARAMS ((U_CHAR *, U_CHAR *, FILE_BUF *));
static void do_line PARAMS ((U_CHAR *, U_CHAR *, FILE_BUF *, struct directive *)); static void do_line PARAMS ((U_CHAR *, U_CHAR *, FILE_BUF *));
static void do_include PARAMS ((U_CHAR *, U_CHAR *, FILE_BUF *, struct directive *)); static void do_include PARAMS ((U_CHAR *, U_CHAR *, FILE_BUF *));
static void do_undef PARAMS ((U_CHAR *, U_CHAR *, FILE_BUF *, struct directive *)); static void do_undef PARAMS ((U_CHAR *, U_CHAR *, FILE_BUF *));
static void do_if PARAMS ((U_CHAR *, U_CHAR *, FILE_BUF *, struct directive *)); static void do_if PARAMS ((U_CHAR *, U_CHAR *, FILE_BUF *));
static void do_xifdef PARAMS ((U_CHAR *, U_CHAR *, FILE_BUF *, struct directive *)); static void do_ifdef PARAMS ((U_CHAR *, U_CHAR *, FILE_BUF *));
static void do_else PARAMS ((U_CHAR *, U_CHAR *, FILE_BUF *, struct directive *)); static void do_ifndef PARAMS ((U_CHAR *, U_CHAR *, FILE_BUF *));
static void do_elif PARAMS ((U_CHAR *, U_CHAR *, FILE_BUF *, struct directive *)); static void do_else PARAMS ((U_CHAR *, U_CHAR *, FILE_BUF *));
static void do_endif PARAMS ((U_CHAR *, U_CHAR *, FILE_BUF *, struct directive *)); static void do_elif PARAMS ((U_CHAR *, U_CHAR *, FILE_BUF *));
static void do_endif PARAMS ((U_CHAR *, U_CHAR *, FILE_BUF *));
static void do_assert PARAMS ((U_CHAR *, U_CHAR *, FILE_BUF *));
static void do_unassert PARAMS ((U_CHAR *, U_CHAR *, FILE_BUF *));
static void do_xifdef PARAMS ((U_CHAR *, U_CHAR *, enum node_type));
static struct hashnode *install PARAMS ((const U_CHAR *, int, enum node_type, int)); static struct hashnode *install PARAMS ((const U_CHAR *, int, enum node_type, int));
static int hashf PARAMS ((const U_CHAR *, int, int)); static int hashf PARAMS ((const U_CHAR *, int, int));
...@@ -353,8 +359,11 @@ static int eval_if_expression PARAMS ((const U_CHAR *, int)); ...@@ -353,8 +359,11 @@ static int eval_if_expression PARAMS ((const U_CHAR *, int));
static void initialize_char_syntax PARAMS ((void)); static void initialize_char_syntax PARAMS ((void));
static void initialize_builtins PARAMS ((void)); static void initialize_builtins PARAMS ((void));
static void make_definition PARAMS ((const U_CHAR *)); static void run_directive PARAMS ((const char *, size_t,
static void make_undef PARAMS ((U_CHAR *)); enum node_type));
static void make_definition PARAMS ((const char *));
static void make_undef PARAMS ((const char *));
static void make_assertion PARAMS ((const char *));
static void grow_outbuf PARAMS ((FILE_BUF *, int)); static void grow_outbuf PARAMS ((FILE_BUF *, int));
static int handle_directive PARAMS ((FILE_BUF *, FILE_BUF *)); static int handle_directive PARAMS ((FILE_BUF *, FILE_BUF *));
...@@ -384,13 +393,15 @@ struct directive directive_table[] = { ...@@ -384,13 +393,15 @@ struct directive directive_table[] = {
{ 6, do_define, "define", T_DEFINE }, { 6, do_define, "define", T_DEFINE },
{ 7, do_include, "include", T_INCLUDE }, { 7, do_include, "include", T_INCLUDE },
{ 5, do_endif, "endif", T_ENDIF }, { 5, do_endif, "endif", T_ENDIF },
{ 5, do_xifdef, "ifdef", T_IFDEF }, { 5, do_ifdef, "ifdef", T_IFDEF },
{ 2, do_if, "if", T_IF, }, { 2, do_if, "if", T_IF, },
{ 4, do_else, "else", T_ELSE }, { 4, do_else, "else", T_ELSE },
{ 6, do_xifdef, "ifndef", T_IFNDEF }, { 6, do_ifndef, "ifndef", T_IFNDEF },
{ 5, do_undef, "undef", T_UNDEF }, { 5, do_undef, "undef", T_UNDEF },
{ 4, do_line, "line", T_LINE }, { 4, do_line, "line", T_LINE },
{ 4, do_elif, "elif", T_ELIF }, { 4, do_elif, "elif", T_ELIF },
{ 6, do_assert, "assert", T_ASSERT },
{ 8, do_unassert,"unassert",T_UNASSERT},
{ -1, 0, "", T_UNUSED}, { -1, 0, "", T_UNUSED},
}; };
...@@ -515,7 +526,6 @@ main (argc, argv) ...@@ -515,7 +526,6 @@ main (argc, argv)
int c = argv[i][1]; int c = argv[i][1];
switch (c) { switch (c) {
case 'A':
case 'E': case 'E':
case '$': case '$':
case 'g': case 'g':
...@@ -604,6 +614,7 @@ main (argc, argv) ...@@ -604,6 +614,7 @@ main (argc, argv)
case 'D': case 'D':
case 'U': case 'U':
case 'A':
{ {
char *p; char *p;
...@@ -614,7 +625,12 @@ main (argc, argv) ...@@ -614,7 +625,12 @@ main (argc, argv)
else else
p = argv[++i]; p = argv[++i];
pend[i].type = c == 'D' ? PD_DEFINE: PD_UNDEF; if (c == 'D')
pend[i].type = PD_DEFINE;
else if (c == 'U')
pend[i].type = PD_UNDEF;
else
pend[i].type = PD_ASSERTION;
pend[i].arg = p; pend[i].arg = p;
} }
break; break;
...@@ -701,9 +717,11 @@ main (argc, argv) ...@@ -701,9 +717,11 @@ main (argc, argv)
/* Do defines specified with -D and undefines specified with -U. */ /* Do defines specified with -D and undefines specified with -U. */
for (i = 1; i < argc; i++) for (i = 1; i < argc; i++)
if (pend[i].type == PD_DEFINE) if (pend[i].type == PD_DEFINE)
make_definition ((const U_CHAR *) pend[i].arg); make_definition (pend[i].arg);
else if (pend[i].type == PD_UNDEF) else if (pend[i].type == PD_UNDEF)
make_undef ((U_CHAR *) pend[i].arg); make_undef (pend[i].arg);
else if (pend[i].type == PD_ASSERTION)
make_assertion (pend[i].arg);
/* Unless -fnostdinc, /* Unless -fnostdinc,
tack on the standard include file dirs to the specified list */ tack on the standard include file dirs to the specified list */
...@@ -2011,7 +2029,7 @@ handle_directive (ip, op) ...@@ -2011,7 +2029,7 @@ handle_directive (ip, op)
the temp buffer if it was necessary to make one. cp the temp buffer if it was necessary to make one. cp
points to the first char after the contents of the (possibly points to the first char after the contents of the (possibly
copied) command, in either case. */ copied) command, in either case. */
(*kt->func) (buf, cp, op, kt); (*kt->func) (buf, cp, op);
check_expand (op, ip->length - (ip->bufp - ip->buf)); check_expand (op, ip->length - (ip->bufp - ip->buf));
return 1; return 1;
...@@ -2172,10 +2190,9 @@ oops: ...@@ -2172,10 +2190,9 @@ oops:
* Expects to see "fname" or <fname> on the input. * Expects to see "fname" or <fname> on the input.
*/ */
static void static void
do_include (buf, limit, op, keyword) do_include (buf, limit, op)
U_CHAR *buf, *limit; U_CHAR *buf, *limit;
FILE_BUF *op; FILE_BUF *op;
struct directive *keyword ATTRIBUTE_UNUSED;
{ {
char *fname; /* Dynamically allocated fname buffer */ char *fname; /* Dynamically allocated fname buffer */
U_CHAR *fbeg, *fend; /* Beginning and end of fname */ U_CHAR *fbeg, *fend; /* Beginning and end of fname */
...@@ -2463,10 +2480,9 @@ LIMIT points to the first character past the end of the definition. ...@@ -2463,10 +2480,9 @@ LIMIT points to the first character past the end of the definition.
KEYWORD is the keyword-table entry for #define. */ KEYWORD is the keyword-table entry for #define. */
static void static void
do_define (buf, limit, op, keyword) do_define (buf, limit, op)
U_CHAR *buf, *limit; U_CHAR *buf, *limit;
FILE_BUF *op ATTRIBUTE_UNUSED; FILE_BUF *op ATTRIBUTE_UNUSED;
struct directive *keyword ATTRIBUTE_UNUSED;
{ {
U_CHAR *bp; /* temp ptr into input buffer */ U_CHAR *bp; /* temp ptr into input buffer */
U_CHAR *symname; /* remember where symbol name starts */ U_CHAR *symname; /* remember where symbol name starts */
...@@ -2874,10 +2890,9 @@ collect_expansion (buf, end, nargs, arglist) ...@@ -2874,10 +2890,9 @@ collect_expansion (buf, end, nargs, arglist)
*/ */
#define FNAME_HASHSIZE 37 #define FNAME_HASHSIZE 37
static void static void
do_line (buf, limit, op, keyword) do_line (buf, limit, op)
U_CHAR *buf, *limit; U_CHAR *buf, *limit;
FILE_BUF *op; FILE_BUF *op;
struct directive *keyword ATTRIBUTE_UNUSED;
{ {
register U_CHAR *bp; register U_CHAR *bp;
FILE_BUF *ip = &instack[indepth]; FILE_BUF *ip = &instack[indepth];
...@@ -2987,11 +3002,10 @@ do_line (buf, limit, op, keyword) ...@@ -2987,11 +3002,10 @@ do_line (buf, limit, op, keyword)
* something that has no definitions, so it isn't one here either. * something that has no definitions, so it isn't one here either.
*/ */
static void static void
do_undef (buf, limit, op, keyword) do_undef (buf, limit, op)
U_CHAR *buf; U_CHAR *buf;
U_CHAR *limit ATTRIBUTE_UNUSED; U_CHAR *limit ATTRIBUTE_UNUSED;
FILE_BUF *op ATTRIBUTE_UNUSED; FILE_BUF *op ATTRIBUTE_UNUSED;
struct directive *keyword ATTRIBUTE_UNUSED;
{ {
HASHNODE *hp; HASHNODE *hp;
...@@ -3007,6 +3021,24 @@ do_undef (buf, limit, op, keyword) ...@@ -3007,6 +3021,24 @@ do_undef (buf, limit, op, keyword)
} }
} }
/* Function body to be provided later. */
static void
do_assert (buf, limit, op)
U_CHAR *buf ATTRIBUTE_UNUSED;
U_CHAR *limit ATTRIBUTE_UNUSED;
FILE_BUF *op ATTRIBUTE_UNUSED;
{
}
/* Function body to be provided later. */
static void
do_unassert (buf, limit, op)
U_CHAR *buf ATTRIBUTE_UNUSED;
U_CHAR *limit ATTRIBUTE_UNUSED;
FILE_BUF *op ATTRIBUTE_UNUSED;
{
}
/* /*
* handle #if command by * handle #if command by
* 1) inserting special `defined' keyword into the hash table * 1) inserting special `defined' keyword into the hash table
...@@ -3020,10 +3052,9 @@ do_undef (buf, limit, op, keyword) ...@@ -3020,10 +3052,9 @@ do_undef (buf, limit, op, keyword)
* or not, depending on the value from step 3. * or not, depending on the value from step 3.
*/ */
static void static void
do_if (buf, limit, op, keyword) do_if (buf, limit, op)
U_CHAR *buf, *limit; U_CHAR *buf, *limit;
FILE_BUF *op ATTRIBUTE_UNUSED; FILE_BUF *op ATTRIBUTE_UNUSED;
struct directive *keyword ATTRIBUTE_UNUSED;
{ {
int value; int value;
FILE_BUF *ip = &instack[indepth]; FILE_BUF *ip = &instack[indepth];
...@@ -3037,10 +3068,9 @@ do_if (buf, limit, op, keyword) ...@@ -3037,10 +3068,9 @@ do_if (buf, limit, op, keyword)
* see the comment above do_else. * see the comment above do_else.
*/ */
static void static void
do_elif (buf, limit, op, keyword) do_elif (buf, limit, op)
U_CHAR *buf, *limit; U_CHAR *buf, *limit;
FILE_BUF *op; FILE_BUF *op;
struct directive *keyword ATTRIBUTE_UNUSED;
{ {
int value; int value;
FILE_BUF *ip = &instack[indepth]; FILE_BUF *ip = &instack[indepth];
...@@ -3103,10 +3133,9 @@ eval_if_expression (buf, length) ...@@ -3103,10 +3133,9 @@ eval_if_expression (buf, length)
* on what directive is actually being processed. * on what directive is actually being processed.
*/ */
static void static void
do_xifdef (buf, limit, op, keyword) do_xifdef (buf, limit, type)
U_CHAR *buf, *limit; U_CHAR *buf, *limit;
FILE_BUF *op ATTRIBUTE_UNUSED; enum node_type type;
struct directive *keyword;
{ {
int skip; int skip;
FILE_BUF *ip = &instack[indepth]; FILE_BUF *ip = &instack[indepth];
...@@ -3119,15 +3148,30 @@ do_xifdef (buf, limit, op, keyword) ...@@ -3119,15 +3148,30 @@ do_xifdef (buf, limit, op, keyword)
/* Find the end of the identifier at the beginning. */ /* Find the end of the identifier at the beginning. */
for (end = buf; is_idchar[*end]; end++); for (end = buf; is_idchar[*end]; end++);
if (end == buf) { if (end == buf)
skip = (keyword->type == T_IFDEF); skip = (type == T_IFDEF);
} else { else
skip = (lookup (buf, end-buf, -1) == NULL) ^ (keyword->type == T_IFNDEF); skip = (lookup (buf, end-buf, -1) == NULL) ^ (type == T_IFNDEF);
}
conditional_skip (ip, skip, T_IF); conditional_skip (ip, skip, T_IF);
} }
static void
do_ifdef (buf, limit, op)
U_CHAR *buf, *limit;
FILE_BUF *op ATTRIBUTE_UNUSED;
{
do_xifdef (buf, limit, T_IFDEF);
}
static void
do_ifndef (buf, limit, op)
U_CHAR *buf, *limit;
FILE_BUF *op ATTRIBUTE_UNUSED;
{
do_xifdef (buf, limit, T_IFNDEF);
}
/* /*
* push TYPE on stack; then, if SKIP is nonzero, skip ahead. * push TYPE on stack; then, if SKIP is nonzero, skip ahead.
*/ */
...@@ -3329,11 +3373,10 @@ skip_if_group (ip, any) ...@@ -3329,11 +3373,10 @@ skip_if_group (ip, any)
* is possible that something different would be better. * is possible that something different would be better.
*/ */
static void static void
do_else (buf, limit, op, keyword) do_else (buf, limit, op)
U_CHAR *buf ATTRIBUTE_UNUSED; U_CHAR *buf ATTRIBUTE_UNUSED;
U_CHAR *limit ATTRIBUTE_UNUSED; U_CHAR *limit ATTRIBUTE_UNUSED;
FILE_BUF *op; FILE_BUF *op;
struct directive *keyword ATTRIBUTE_UNUSED;
{ {
FILE_BUF *ip = &instack[indepth]; FILE_BUF *ip = &instack[indepth];
...@@ -3363,11 +3406,10 @@ do_else (buf, limit, op, keyword) ...@@ -3363,11 +3406,10 @@ do_else (buf, limit, op, keyword)
* unstack after #endif command * unstack after #endif command
*/ */
static void static void
do_endif (buf, limit, op, keyword) do_endif (buf, limit, op)
U_CHAR *buf ATTRIBUTE_UNUSED; U_CHAR *buf ATTRIBUTE_UNUSED;
U_CHAR *limit ATTRIBUTE_UNUSED; U_CHAR *limit ATTRIBUTE_UNUSED;
FILE_BUF *op; FILE_BUF *op;
struct directive *keyword ATTRIBUTE_UNUSED;
{ {
if (if_stack == instack[indepth].if_stack) if (if_stack == instack[indepth].if_stack)
error ("unbalanced #endif"); error ("unbalanced #endif");
...@@ -4663,77 +4705,100 @@ initialize_builtins () ...@@ -4663,77 +4705,100 @@ initialize_builtins ()
#undef install_spec #undef install_spec
#undef install_value #undef install_value
/* /* Common handler of command line directives -U, -D and -A. */
* process a given definition string, for initialization
* If STR is just an identifier, define it with value 1.
* If STR has anything after the identifier, then it should
* be identifier-space-definition.
*/
static void static void
make_definition (str) run_directive (str, len, type)
const U_CHAR *str; const char *str;
size_t len;
enum node_type type;
{ {
FILE_BUF *ip;
struct directive *kt; struct directive *kt;
U_CHAR *buf; FILE_BUF *ip = &instack[++indepth];
const U_CHAR *p; ip->fname = "*command line*";
size_t len = strlen ((const char *)str);
p = (const U_CHAR *) strchr ((const char *)str, '=');
if (p == NULL) {
/* Change -DFOO into #define FOO 1 */
buf = (U_CHAR *) alloca (len + 3);
memcpy (buf, str, len);
memcpy (buf + len, " 1", 3);
len += 2;
} else {
buf = (U_CHAR *) alloca (len + 1);
memcpy (buf, str, len + 1);
buf[p - str] = ' ';
}
ip = &instack[++indepth]; ip->buf = ip->bufp = (U_CHAR *) str;
ip->fname = "*Initialization*";
ip->buf = ip->bufp = buf;
ip->length = len; ip->length = len;
ip->lineno = 1; ip->lineno = 1;
ip->macro = 0; ip->macro = 0;
ip->free_ptr = 0; ip->free_ptr = 0;
ip->if_stack = if_stack; ip->if_stack = if_stack;
for (kt = directive_table; kt->type != T_DEFINE; kt++) for (kt = directive_table; kt->type != type; kt++)
; ;
/* pass NULL as output ptr to do_define since we KNOW it never (*kt->func) ((U_CHAR *) str, (U_CHAR *) str + len, NULL);
does any output.... */
do_define (buf, buf + ip->length, NULL, kt);
--indepth; --indepth;
} }
/* JF, this does the work for the -U option */ /* Handle the -D option. If STR is just an identifier, define it with
* value 1. If STR has anything after the identifier, then it should
* be identifier-space-definition. */
static void
make_definition (str)
const char *str;
{
char *buf, *p;
size_t count;
/* Copy the entire option so we can modify it.
Change the first "=" in the string to a space. If there is none,
tack " 1" on the end. */
/* Length including the null. */
count = strlen (str);
buf = (char *) alloca (count + 2);
memcpy (buf, str, count);
p = strchr (str, '=');
if (p)
buf[p - str] = ' ';
else
{
buf[count++] = ' ';
buf[count++] = '1';
}
run_directive (buf, count, T_DEFINE);
}
/* Handle the -U option. */
static void static void
make_undef (str) make_undef (str)
U_CHAR *str; const char *str;
{ {
FILE_BUF *ip; run_directive (str, strlen (str), T_UNDEF);
struct directive *kt; }
ip = &instack[++indepth]; /* Handles the #assert (-A) and #unassert (-A-) command line options. */
ip->fname = "*undef*"; static void
make_assertion (str)
const char *str;
{
enum node_type type = T_ASSERT;
size_t count;
const char *p;
ip->buf = ip->bufp = str; if (*str == '-')
ip->length = strlen ((const char *)str); {
ip->lineno = 1; str++;
ip->macro = 0; type = T_UNASSERT;
ip->free_ptr = 0; }
ip->if_stack = if_stack;
for (kt = directive_table; kt->type != T_UNDEF; kt++) count = strlen (str);
; p = strchr (str, '=');
if (p)
{
/* Copy the entire option so we can modify it. Change the first
"=" in the string to a '(', and tack a ')' on the end. */
char *buf = (char *) alloca (count + 1);
do_undef (str, str + ip->length, NULL, kt); memcpy (buf, str, count);
--indepth; buf[p - str] = '(';
buf[count++] = ')';
str = buf;
}
run_directive (str, count, type);
} }
/* Add output to `deps_buffer' for the -M switch. /* Add output to `deps_buffer' for the -M switch.
......
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