/* Parse C expressions for CCCP.
- Copyright (C) 1987, 1992, 1994, 1995 Free Software Foundation.
+ Copyright (C) 1987, 1992, 1994, 1995, 1997 Free Software Foundation.
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
You are forbidden to forbid anyone else to use, share and improve
what you give them. Help stamp out software-hoarding!
-Written by Per Bothner 1994. */
+Written by Per Bothner 1994. */
/* Parse a C expression from text in a string */
#endif
#ifndef NULL_PTR
-#define NULL_PTR ((GENERIC_PTR)0)
+#define NULL_PTR ((GENERIC_PTR) 0)
#endif
extern char *xmalloc ();
#define RIGHT_OPERAND_REQUIRED 2
#define HAVE_VALUE 4
/* SKIP_OPERAND is set for '&&' '||' '?' and ':' when the
- following operand should be short-circuited instead of evaluated. */
+ following operand should be short-circuited instead of evaluated. */
#define SKIP_OPERAND 8
/*#define UNSIGNEDP 16*/
struct operation {
short op;
- char rprio; /* Priority of op (relative to it right operand). */
+ char rprio; /* Priority of op (relative to it right operand). */
char flags;
char unsignedp; /* true if value should be treated as unsigned */
- HOST_WIDE_INT value; /* The value logically "right" of op. */
+ HOST_WIDE_INT value; /* The value logically "right" of op. */
};
\f
/* Take care of parsing a number (anything that starts with a digit).
else if (*p == '0')
base = 8;
- /* Some buggy compilers (e.g. MPW C) seem to need both casts. */
+ /* Some buggy compilers (e.g. MPW C) seem to need both casts. */
ULONG_MAX_over_base = ((unsigned long) -1) / ((unsigned long) base);
for (; len > 0; len--) {
}
if (base <= largest_digit)
- cpp_warning (pfile, "integer constant contains digits beyond the radix");
+ cpp_pedwarn (pfile, "integer constant contains digits beyond the radix");
if (overflow)
- cpp_warning (pfile, "integer constant out of range");
+ cpp_pedwarn (pfile, "integer constant out of range");
/* If too big to be signed, consider it unsigned. */
if ((long) n < 0 && ! op.unsignedp)
{NULL, ERROR}
};
-/* Read one token. */
+/* Read one token. */
struct operation
cpp_lex (pfile)
-cpp_reader *pfile;
+ cpp_reader *pfile;
{
register int c;
register int namelen;
pfile->limit = tok_start;
switch (token)
{
- case CPP_EOF: /* Should not happen ... */
+ case CPP_EOF: /* Should not happen ... */
case CPP_VSPACE:
op.op = 0;
return op;
if (mbtowc (& wc, token_buffer, num_chars) == num_chars)
result = wc;
else
- cpp_warning (pfile,"Ignoring invalid multibyte character");
+ cpp_pedwarn (pfile,"Ignoring invalid multibyte character");
}
#endif
op.value = result;
if ((i & ~((1 << MAX_CHAR_TYPE_SIZE) - 1)) != 0)
{
i &= (1 << MAX_CHAR_TYPE_SIZE) - 1;
- cpp_warning (pfile,
+ cpp_pedwarn (pfile,
"octal character constant does not fit in a byte");
}
return i;
if (overflow | (i & ~((1 << BITS_PER_UNIT) - 1)))
{
i &= (1 << BITS_PER_UNIT) - 1;
- cpp_warning (pfile,
+ cpp_pedwarn (pfile,
"hex character constant does not fit in a byte");
}
return i;
return a >> b;
}
\f
-/* These priorities are all even, so we can handle associatively. */
+/* These priorities are all even, so we can handle associatively. */
#define PAREN_INNER_PRIO 0
#define COMMA_PRIO 4
#define COND_PRIO (COMMA_PRIO+2)
/* See if the token is an operand, in which case go to set_value.
If the token is an operator, figure out its left and right
- priorities, and then goto maybe_reduce. */
+ priorities, and then goto maybe_reduce. */
switch (op.op)
{
}
set_value:
- /* Push a value onto the stack. */
+ /* Push a value onto the stack. */
if (top->flags & HAVE_VALUE)
{
cpp_error (pfile, "syntax error in #if");
continue;
maybe_reduce:
- /* Push an operator, and check if we can reduce now. */
+ /* Push an operator, and check if we can reduce now. */
while (top->rprio > lprio)
{
long v1 = top[-1].value, v2 = top[0].value;
}
break;
case '-':
- if (skip_evaluation) ; /* do nothing */
- else if (!(top->flags & HAVE_VALUE))
+ if (!(top->flags & HAVE_VALUE))
{ /* Unary '-' */
top->value = - v2;
- if ((top->value & v2) < 0 && ! unsigned2)
+ if (!skip_evaluation && (top->value & v2) < 0 && !unsigned2)
integer_overflow (pfile);
top->unsignedp = unsigned2;
top->flags |= HAVE_VALUE;
{ /* Binary '-' */
top->value = v1 - v2;
top->unsignedp = unsigned1 || unsigned2;
- if (! top->unsignedp
+ if (! top->unsignedp && ! skip_evaluation
&& ! possible_sum_sign (top->value, v2, v1))
integer_overflow (pfile);
}
}
top++;
- /* Check for and handle stack overflow. */
+ /* Check for and handle stack overflow. */
if (top == limit)
{
struct operation *new_stack;
- int old_size = (char*)limit - (char*)stack;
+ int old_size = (char *) limit - (char *) stack;
int new_size = 2 * old_size;
if (stack != init_stack)
- new_stack = (struct operation*) xrealloc (stack, new_size);
+ new_stack = (struct operation *) xrealloc (stack, new_size);
else
{
- new_stack = (struct operation*) xmalloc (new_size);
+ new_stack = (struct operation *) xmalloc (new_size);
bcopy ((char *) stack, (char *) new_stack, old_size);
}
stack = new_stack;
- top = (struct operation*)((char*) new_stack + old_size);
- limit = (struct operation*)((char*) new_stack + new_size);
+ top = (struct operation *) ((char *) new_stack + old_size);
+ limit = (struct operation *) ((char *) new_stack + new_size);
}
top->flags = flags;