1 /* Parse C expressions for cpplib.
2 Copyright (C) 1987, 1992, 1994, 1995, 1997, 1998, 1999, 2000, 2001,
3 2002 Free Software Foundation.
4 Contributed by Per Bothner, 1994.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
26 /* Yield nonzero if adding two numbers with A's and B's signs can yield a
27 number with SUM's sign, where A, B, and SUM are all C integers. */
28 #define possible_sum_sign(a, b, sum) ((((a) ^ (b)) | ~ ((a) ^ (sum))) < 0)
30 static void integer_overflow PARAMS ((cpp_reader *));
31 static HOST_WIDEST_INT left_shift PARAMS ((cpp_reader *, HOST_WIDEST_INT,
33 unsigned HOST_WIDEST_INT));
34 static HOST_WIDEST_INT right_shift PARAMS ((cpp_reader *, HOST_WIDEST_INT,
36 unsigned HOST_WIDEST_INT));
37 static struct op parse_number PARAMS ((cpp_reader *, const cpp_token *));
38 static struct op parse_defined PARAMS ((cpp_reader *));
39 static struct op lex PARAMS ((cpp_reader *, int));
40 static const unsigned char *op_as_text PARAMS ((cpp_reader *, enum cpp_ttype));
45 uchar prio; /* Priority of op. */
47 uchar unsignedp; /* True if value should be treated as unsigned. */
48 HOST_WIDEST_INT value; /* The value logically "right" of op. */
51 /* Token type abuse. There is no "error" token, but we can't get
52 comments in #if, so we can abuse that token type. Similarly,
53 create unary plus and minus operators. */
54 #define CPP_ERROR CPP_COMMENT
55 #define CPP_UPLUS (CPP_LAST_CPP_OP + 1)
56 #define CPP_UMINUS (CPP_LAST_CPP_OP + 2)
58 /* With -O2, gcc appears to produce nice code, moving the error
59 message load and subsequent jump completely out of the main path. */
60 #define SYNTAX_ERROR(msgid) \
61 do { cpp_error (pfile, DL_ERROR, msgid); goto syntax_error; } while(0)
62 #define SYNTAX_ERROR2(msgid, arg) \
63 do { cpp_error (pfile, DL_ERROR, msgid, arg); goto syntax_error; } while(0)
67 const unsigned char s[4];
68 const unsigned char u;
69 const unsigned char l;
72 static const struct suffix vsuf_1[] = {
73 { "u", 1, 0 }, { "U", 1, 0 },
74 { "l", 0, 1 }, { "L", 0, 1 }
77 static const struct suffix vsuf_2[] = {
78 { "ul", 1, 1 }, { "UL", 1, 1 }, { "uL", 1, 1 }, { "Ul", 1, 1 },
79 { "lu", 1, 1 }, { "LU", 1, 1 }, { "Lu", 1, 1 }, { "lU", 1, 1 },
80 { "ll", 0, 2 }, { "LL", 0, 2 }
83 static const struct suffix vsuf_3[] = {
84 { "ull", 1, 2 }, { "ULL", 1, 2 }, { "uLL", 1, 2 }, { "Ull", 1, 2 },
85 { "llu", 1, 2 }, { "LLU", 1, 2 }, { "LLu", 1, 2 }, { "llU", 1, 2 }
88 /* Parse and convert what is presumably an integer in TOK. Accepts
89 decimal, hex, or octal with or without size suffixes. Returned op
90 is CPP_ERROR on error, otherwise it is a CPP_NUMBER. */
92 parse_number (pfile, tok)
97 const uchar *start = tok->val.str.text;
98 const uchar *end = start + tok->val.str.len;
99 const uchar *p = start;
101 unsigned HOST_WIDEST_INT n = 0, nd, MAX_over_base;
104 int digit, largest_digit = 0;
105 const struct suffix *sufftab;
111 if (end - start >= 3 && (p[1] == 'x' || p[1] == 'X'))
123 /* Some buggy compilers (e.g. MPW C) seem to need both casts. */
124 MAX_over_base = (((unsigned HOST_WIDEST_INT) -1)
125 / ((unsigned HOST_WIDEST_INT) base));
132 || (base == 16 && ISXDIGIT (c)))
133 digit = hex_value (c);
137 if (largest_digit < digit)
138 largest_digit = digit;
139 nd = n * base + digit;
140 overflow |= MAX_over_base < n || nd < n;
146 /* Check for a floating point constant. Note that float constants
147 with an exponent or suffix but no decimal point are technically
148 invalid (C99 6.4.4.2) but accepted elsewhere. */
149 if ((c == '.' || c == 'F' || c == 'f')
150 || (base == 10 && (c == 'E' || c == 'e')
151 && p+1 < end && (p[1] == '+' || p[1] == '-'))
152 || (base == 16 && (c == 'P' || c == 'p')
153 && p+1 < end && (p[1] == '+' || p[1] == '-')))
154 SYNTAX_ERROR ("floating point numbers are not valid in #if");
156 /* Determine the suffix. l means long, and u means unsigned.
157 See the suffix tables, above. */
160 case 1: sufftab = vsuf_1; nsuff = ARRAY_SIZE (vsuf_1); break;
161 case 2: sufftab = vsuf_2; nsuff = ARRAY_SIZE (vsuf_2); break;
162 case 3: sufftab = vsuf_3; nsuff = ARRAY_SIZE (vsuf_3); break;
163 default: goto invalid_suffix;
166 for (i = 0; i < nsuff; i++)
167 if (memcmp (p, sufftab[i].s, end - p) == 0)
171 op.unsignedp = sufftab[i].u;
173 if (CPP_WTRADITIONAL (pfile)
175 && ! cpp_sys_macro_p (pfile))
176 cpp_error (pfile, DL_WARNING, "traditional C rejects the `U' suffix");
177 if (sufftab[i].l == 2 && CPP_OPTION (pfile, pedantic)
178 && ! CPP_OPTION (pfile, c99))
179 cpp_error (pfile, DL_PEDWARN,
180 "too many 'l' suffixes in integer constant");
183 if (base <= largest_digit)
184 cpp_error (pfile, DL_PEDWARN,
185 "integer constant contains digits beyond the radix");
188 cpp_error (pfile, DL_PEDWARN, "integer constant out of range");
190 /* If too big to be signed, consider it unsigned. */
191 else if ((HOST_WIDEST_INT) n < 0 && ! op.unsignedp)
194 cpp_error (pfile, DL_WARNING,
195 "integer constant is so large that it is unsigned");
204 cpp_error (pfile, DL_ERROR, "invalid suffix '%.*s' on integer constant",
211 /* Handle meeting "defined" in a preprocessor expression. */
213 parse_defined (pfile)
217 cpp_hashnode *node = 0;
218 const cpp_token *token;
220 cpp_context *initial_context = pfile->context;
222 /* Don't expand macros. */
223 pfile->state.prevent_expansion++;
225 token = cpp_get_token (pfile);
226 if (token->type == CPP_OPEN_PAREN)
229 token = cpp_get_token (pfile);
232 if (token->type == CPP_NAME)
234 node = token->val.node;
235 if (paren && cpp_get_token (pfile)->type != CPP_CLOSE_PAREN)
237 cpp_error (pfile, DL_ERROR, "missing ')' after \"defined\"");
243 cpp_error (pfile, DL_ERROR,
244 "operator \"defined\" requires an identifier");
245 if (token->flags & NAMED_OP)
250 op.type = token->type;
251 cpp_error (pfile, DL_ERROR,
252 "(\"%s\" is an alternative token for \"%s\" in C++)",
253 cpp_token_as_text (pfile, token),
254 cpp_token_as_text (pfile, &op));
262 if (pfile->context != initial_context)
263 cpp_error (pfile, DL_WARNING,
264 "this use of \"defined\" may not be portable");
266 op.value = node->type == NT_MACRO;
270 /* A possible controlling macro of the form #if !defined ().
271 _cpp_parse_expr checks there was no other junk on the line. */
272 pfile->mi_ind_cmacro = node;
275 pfile->state.prevent_expansion--;
279 /* Read a token. The returned type is CPP_NUMBER for a valid number
280 (an interpreted preprocessing number or character constant, or the
281 result of the "defined" or "#" operators), CPP_ERROR on error,
282 CPP_EOF, or the type of an operator token. */
284 lex (pfile, skip_evaluation)
289 const cpp_token *token = cpp_get_token (pfile);
294 return parse_number (pfile, token);
299 unsigned int chars_seen;
301 if (token->type == CPP_CHAR)
304 op.unsignedp = WCHAR_UNSIGNED;
306 op.value = cpp_interpret_charconst (pfile, token, 1, &chars_seen);
312 SYNTAX_ERROR ("string constants are not valid in #if");
315 if (ISGRAPH (token->val.c))
316 SYNTAX_ERROR2 ("invalid character '%c' in #if", token->val.c);
318 SYNTAX_ERROR2 ("invalid character '\\%03o' in #if", token->val.c);
321 if (token->val.node == pfile->spec_nodes.n_defined)
322 return parse_defined (pfile);
323 else if (CPP_OPTION (pfile, cplusplus)
324 && (token->val.node == pfile->spec_nodes.n_true
325 || token->val.node == pfile->spec_nodes.n_false))
329 op.value = (token->val.node == pfile->spec_nodes.n_true);
331 /* Warn about use of true or false in #if when pedantic
332 and stdbool.h has not been included. */
333 if (CPP_PEDANTIC (pfile)
334 && ! cpp_defined (pfile, DSC("__bool_true_false_are_defined")))
335 cpp_error (pfile, DL_PEDWARN,
336 "ISO C++ does not permit \"%s\" in #if",
337 NODE_NAME (token->val.node));
346 if (CPP_OPTION (pfile, warn_undef) && !skip_evaluation)
347 cpp_error (pfile, DL_WARNING, "\"%s\" is not defined",
348 NODE_NAME (token->val.node));
357 if (_cpp_test_assertion (pfile, &temp))
365 if (((int) token->type > (int) CPP_EQ
366 && (int) token->type < (int) CPP_PLUS_EQ)
367 || token->type == CPP_EOF)
373 SYNTAX_ERROR2 ("\"%s\" is not valid in #if expressions",
374 cpp_token_as_text (pfile, token));
382 /* Warn if appropriate on overflow. */
384 integer_overflow (pfile)
387 if (CPP_PEDANTIC (pfile))
388 cpp_error (pfile, DL_PEDWARN,
389 "integer overflow in preprocessor expression");
392 /* Handle shifting A left by B bits. UNSIGNEDP is non-zero if A is
394 static HOST_WIDEST_INT
395 left_shift (pfile, a, unsignedp, b)
398 unsigned int unsignedp;
399 unsigned HOST_WIDEST_INT b;
401 if (b >= HOST_BITS_PER_WIDEST_INT)
403 if (! unsignedp && a != 0)
404 integer_overflow (pfile);
408 return (unsigned HOST_WIDEST_INT) a << b;
411 HOST_WIDEST_INT l = a << b;
413 integer_overflow (pfile);
418 /* Handle shifting A right by B bits. UNSIGNEDP is non-zero if A is
420 static HOST_WIDEST_INT
421 right_shift (pfile, a, unsignedp, b)
422 cpp_reader *pfile ATTRIBUTE_UNUSED;
424 unsigned int unsignedp;
425 unsigned HOST_WIDEST_INT b;
427 if (b >= HOST_BITS_PER_WIDEST_INT)
428 return unsignedp ? 0 : a >> (HOST_BITS_PER_WIDEST_INT - 1);
430 return (unsigned HOST_WIDEST_INT) a >> b;
435 /* Operator precedence and flags table.
437 After an operator is returned from the lexer, if it has priority less
438 than or equal to the operator on the top of the stack, we reduce the
439 stack by one operator and repeat the test. Since equal priorities
440 reduce, this is naturally left-associative.
442 We handle right-associative operators by clearing the lower bit of all
443 left-associative operators, and setting it for right-associative ones.
444 After the reduction phase of a new operator, just before it is pushed
445 onto the stack, its RIGHT_ASSOC bit is cleared. The effect is that
446 during the reduction phase, the current right-associative operator has
447 a priority one greater than any other operator of otherwise equal
448 precedence that has been pushed on the top of the stack. This avoids
449 a reduction pass, and effectively makes the logic right-associative.
451 The remaining cases are '(' and ')'. We handle '(' by skipping the
452 reduction phase completely. ')' is given lower priority than
453 everything else, including '(', effectively forcing a reduction of the
454 parenthesised expression. If there is no matching '(', the stack will
455 be reduced all the way to the beginning, exiting the parser in the
456 same way as the ultra-low priority end-of-expression dummy operator.
457 The exit code checks to see if the operator that caused it is ')', and
458 if so outputs an appropriate error message.
460 The parser assumes all shifted operators require a left operand unless
461 the flag NO_L_OPERAND is set. These semantics are automatic; any
462 extra semantics need to be handled with operator-specific code. */
465 #define FLAG_MASK ((1 << FLAG_BITS) - 1)
466 #define PRIO_SHIFT (FLAG_BITS + 1)
467 #define EXTRACT_PRIO(CNST) ((CNST) >> FLAG_BITS)
468 #define EXTRACT_FLAGS(CNST) ((CNST) & FLAG_MASK)
471 #define NO_L_OPERAND (1 << 0)
472 #define SHORT_CIRCUIT (1 << 1)
474 /* Priority and flag combinations. */
475 #define RIGHT_ASSOC (1 << FLAG_BITS)
476 #define FORCE_REDUCE_PRIO (0 << PRIO_SHIFT)
477 #define CLOSE_PAREN_PRIO (1 << PRIO_SHIFT)
478 #define OPEN_PAREN_PRIO ((2 << PRIO_SHIFT) | NO_L_OPERAND)
479 #define COMMA_PRIO (3 << PRIO_SHIFT)
480 #define COND_PRIO ((4 << PRIO_SHIFT) | RIGHT_ASSOC | SHORT_CIRCUIT)
481 #define COLON_PRIO ((5 << PRIO_SHIFT) | SHORT_CIRCUIT)
482 #define OROR_PRIO ((6 << PRIO_SHIFT) | SHORT_CIRCUIT)
483 #define ANDAND_PRIO ((7 << PRIO_SHIFT) | SHORT_CIRCUIT)
484 #define OR_PRIO (8 << PRIO_SHIFT)
485 #define XOR_PRIO (9 << PRIO_SHIFT)
486 #define AND_PRIO (10 << PRIO_SHIFT)
487 #define MINMAX_PRIO (11 << PRIO_SHIFT)
488 #define EQUAL_PRIO (12 << PRIO_SHIFT)
489 #define LESS_PRIO (13 << PRIO_SHIFT)
490 #define SHIFT_PRIO (14 << PRIO_SHIFT)
491 #define PLUS_PRIO (15 << PRIO_SHIFT)
492 #define MUL_PRIO (16 << PRIO_SHIFT)
493 #define UNARY_PRIO ((17 << PRIO_SHIFT) | RIGHT_ASSOC | NO_L_OPERAND)
495 /* Operator to priority map. Must be in the same order as the first
496 N entries of enum cpp_ttype. */
500 /* EQ */ 0, /* dummy entry - can't happen */
501 /* NOT */ UNARY_PRIO,
502 /* GREATER */ LESS_PRIO,
503 /* LESS */ LESS_PRIO,
504 /* PLUS */ PLUS_PRIO,
505 /* MINUS */ PLUS_PRIO,
512 /* RSHIFT */ SHIFT_PRIO,
513 /* LSHIFT */ SHIFT_PRIO,
514 /* MIN */ MINMAX_PRIO, /* C++ specific */
515 /* MAX */ MINMAX_PRIO, /* extensions */
517 /* COMPL */ UNARY_PRIO,
518 /* AND_AND */ ANDAND_PRIO,
519 /* OR_OR */ OROR_PRIO,
520 /* QUERY */ COND_PRIO,
521 /* COLON */ COLON_PRIO,
522 /* COMMA */ COMMA_PRIO,
523 /* OPEN_PAREN */ OPEN_PAREN_PRIO,
524 /* CLOSE_PAREN */ CLOSE_PAREN_PRIO,
525 /* EQ_EQ */ EQUAL_PRIO,
526 /* NOT_EQ */ EQUAL_PRIO,
527 /* GREATER_EQ */ LESS_PRIO,
528 /* LESS_EQ */ LESS_PRIO,
529 /* EOF */ FORCE_REDUCE_PRIO,
530 /* UPLUS */ UNARY_PRIO,
531 /* UMINUS */ UNARY_PRIO
534 #define COMPARE(OP) \
535 top->unsignedp = 0; \
536 top->value = (unsigned1 | unsigned2) \
537 ? (unsigned HOST_WIDEST_INT) v1 OP (unsigned HOST_WIDEST_INT) v2 \
539 #define EQUALITY(OP) \
540 top->value = v1 OP v2; \
542 #define BITWISE(OP) \
543 top->value = v1 OP v2; \
544 top->unsignedp = unsigned1 | unsigned2;
546 top->value = (v1 OP v2) ? v1 : v2; \
547 top->unsignedp = unsigned1 | unsigned2;
549 top->value = OP v2; \
550 top->unsignedp = unsigned2;
551 #define SHIFT(PSH, MSH) \
552 if (skip_evaluation) \
554 top->unsignedp = unsigned1; \
555 if (v2 < 0 && ! unsigned2) \
556 top->value = MSH (pfile, v1, unsigned1, -v2); \
558 top->value = PSH (pfile, v1, unsigned1, v2);
560 /* Parse and evaluate a C expression, reading from PFILE.
561 Returns the truth value of the expression. */
563 _cpp_parse_expr (pfile)
566 /* The implementation is an operator precedence parser, i.e. a
567 bottom-up parser, using a stack for not-yet-reduced tokens.
569 The stack base is 'stack', and the current stack pointer is 'top'.
570 There is a stack element for each operator (only),
571 and the most recently pushed operator is 'top->op'.
572 An operand (value) is stored in the 'value' field of the stack
573 element of the operator that precedes it. */
575 #define INIT_STACK_SIZE 20
576 struct op init_stack[INIT_STACK_SIZE];
577 struct op *stack = init_stack;
578 struct op *limit = stack + INIT_STACK_SIZE;
579 struct op *top = stack + 1;
580 int skip_evaluation = 0;
582 unsigned int lex_count, saw_leading_not;
583 bool want_value = true;
585 /* Set up detection of #if ! defined(). */
586 pfile->mi_ind_cmacro = 0;
590 /* We've finished when we try to reduce this. */
592 /* Nifty way to catch missing '('. */
593 top->prio = EXTRACT_PRIO(CLOSE_PAREN_PRIO);
602 op = lex (pfile, skip_evaluation);
605 /* If the token is an operand, push its value and get next
606 token. If it is an operator, handle some special cases, get
607 its priority and flags, and try to reduce the expression on
614 /* Push a value onto the stack. */
616 SYNTAX_ERROR ("missing binary operator");
619 top->value = op.value;
620 top->unsignedp = op.unsignedp;
624 saw_leading_not = lex_count == 1;
638 flags = EXTRACT_FLAGS (op_to_prio[op.op]);
639 prio = EXTRACT_PRIO (op_to_prio[op.op]);
640 if (prio == EXTRACT_PRIO (OPEN_PAREN_PRIO))
643 /* Check for reductions. Then push the operator. */
644 while (prio <= top->prio)
646 HOST_WIDEST_INT v1, v2;
647 unsigned int unsigned1, unsigned2;
649 /* Most operators that can appear on the stack require a
650 right operand. Check this before trying to reduce. */
653 if (top->op == CPP_OPEN_PAREN)
654 SYNTAX_ERROR ("void expression between '(' and ')'");
655 else if (top->op != CPP_EOF)
656 SYNTAX_ERROR2 ("operator '%s' has no right operand",
657 op_as_text (pfile, top->op));
658 else if (op.op != CPP_CLOSE_PAREN)
659 SYNTAX_ERROR ("#if with no expression");
662 unsigned2 = top->unsignedp, v2 = top->value;
664 unsigned1 = top->unsignedp, v1 = top->value;
666 /* Now set top->value = (top[1].op)(v1, v2); */
670 cpp_error (pfile, DL_ICE, "impossible operator '%s'",
671 op_as_text (pfile, top[1].op));
674 case CPP_NOT: UNARY(!); break;
675 case CPP_COMPL: UNARY(~); break;
676 case CPP_LESS: COMPARE(<); break;
677 case CPP_GREATER: COMPARE(>); break;
678 case CPP_LESS_EQ: COMPARE(<=); break;
679 case CPP_GREATER_EQ: COMPARE(>=); break;
680 case CPP_EQ_EQ: EQUALITY(==); break;
681 case CPP_NOT_EQ: EQUALITY(!=); break;
682 case CPP_AND: BITWISE(&); break;
683 case CPP_XOR: BITWISE(^); break;
684 case CPP_OR: BITWISE(|); break;
685 case CPP_LSHIFT: SHIFT(left_shift, right_shift); break;
686 case CPP_RSHIFT: SHIFT(right_shift, left_shift); break;
687 case CPP_MIN: MINMAX(<); break;
688 case CPP_MAX: MINMAX(>); break;
691 /* Can't use UNARY(+) because K+R C did not have unary
692 plus. Can't use UNARY() because some compilers object
693 to the empty argument. */
695 top->unsignedp = unsigned2;
696 if (CPP_WTRADITIONAL (pfile))
697 cpp_error (pfile, DL_WARNING,
698 "traditional C rejects the unary plus operator");
702 if (!skip_evaluation && (top->value & v2) < 0 && !unsigned2)
703 integer_overflow (pfile);
707 top->value = v1 + v2;
708 top->unsignedp = unsigned1 | unsigned2;
709 if (! top->unsignedp && ! skip_evaluation
710 && ! possible_sum_sign (v1, v2, top->value))
711 integer_overflow (pfile);
714 top->value = v1 - v2;
715 top->unsignedp = unsigned1 | unsigned2;
716 if (! top->unsignedp && ! skip_evaluation
717 && ! possible_sum_sign (top->value, v2, v1))
718 integer_overflow (pfile);
721 top->unsignedp = unsigned1 | unsigned2;
723 top->value = (unsigned HOST_WIDEST_INT) v1 * v2;
724 else if (!skip_evaluation)
726 top->value = v1 * v2;
727 if (v1 && (top->value / v1 != v2
728 || (top->value & v1 & v2) < 0))
729 integer_overflow (pfile);
737 SYNTAX_ERROR ("division by zero in #if");
738 top->unsignedp = unsigned1 | unsigned2;
739 if (top[1].op == CPP_DIV)
742 top->value = (unsigned HOST_WIDEST_INT) v1 / v2;
745 top->value = v1 / v2;
746 if ((top->value & v1 & v2) < 0)
747 integer_overflow (pfile);
753 top->value = (unsigned HOST_WIDEST_INT) v1 % v2;
755 top->value = v1 % v2;
760 top->value = v1 || v2;
762 if (v1) skip_evaluation--;
765 top->value = v1 && v2;
767 if (!v1) skip_evaluation--;
770 if (CPP_PEDANTIC (pfile))
771 cpp_error (pfile, DL_PEDWARN,
772 "comma operator in operand of #if");
774 top->unsignedp = unsigned2;
777 SYNTAX_ERROR ("syntax error '?' without following ':'");
779 if (top[0].op != CPP_QUERY)
780 SYNTAX_ERROR ("syntax error ':' without preceding '?'");
782 if (top->value) skip_evaluation--;
783 top->value = top->value ? v1 : v2;
784 top->unsignedp = unsigned1 | unsigned2;
787 if (op.op != CPP_CLOSE_PAREN)
788 SYNTAX_ERROR ("missing ')' in expression");
790 op.unsignedp = unsigned2;
793 /* Reducing this dummy operator indicates we've finished. */
794 if (op.op == CPP_CLOSE_PAREN)
795 SYNTAX_ERROR ("missing '(' in expression");
800 /* Handle short-circuit evaluations. */
801 if (flags & SHORT_CIRCUIT)
804 case CPP_OR_OR: if (top->value) skip_evaluation++; break;
806 case CPP_QUERY: if (!top->value) skip_evaluation++; break;
808 if (top[-1].value) /* Was '?' condition true? */
817 /* Check we have a left operand iff we need one. */
818 if (flags & NO_L_OPERAND)
821 SYNTAX_ERROR2 ("missing binary operator before '%s'",
822 op_as_text (pfile, op.op));
827 SYNTAX_ERROR2 ("operator '%s' has no left operand",
828 op_as_text (pfile, op.op));
832 /* Check for and handle stack overflow. */
836 struct op *new_stack;
837 int old_size = (char *) limit - (char *) stack;
838 int new_size = 2 * old_size;
839 if (stack != init_stack)
840 new_stack = (struct op *) xrealloc (stack, new_size);
843 new_stack = (struct op *) xmalloc (new_size);
844 memcpy (new_stack, stack, old_size);
847 top = (struct op *) ((char *) new_stack + old_size);
848 limit = (struct op *) ((char *) new_stack + new_size);
852 top->prio = prio & ~EXTRACT_PRIO(RIGHT_ASSOC);
857 /* The controlling macro expression is only valid if we called lex 3
858 times: <!> <defined expression> and <EOF>. push_conditional ()
859 checks that we are at top-of-file. */
860 if (pfile->mi_ind_cmacro && !(saw_leading_not && lex_count == 3))
861 pfile->mi_ind_cmacro = 0;
863 result = (top[1].value != 0);
867 cpp_error (pfile, DL_ICE, "unbalanced stack in #if");
869 result = 0; /* Return 0 on syntax error. */
872 /* Free dynamic stack if we allocated one. */
873 if (stack != init_stack)
878 /* Output OP as text for diagnostics. */
879 static const unsigned char *
880 op_as_text (pfile, op)
888 else if (op == CPP_UMINUS)
893 return cpp_token_as_text (pfile, &token);