]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libcpp/expr.c
1 /* Parse C expressions for cpplib.
2 Copyright (C) 1987, 1992, 1994, 1995, 1997, 1998, 1999, 2000, 2001,
3 2002, 2004, 2008 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, 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA. */
26 #define PART_PRECISION (sizeof (cpp_num_part) * CHAR_BIT)
27 #define HALF_MASK (~(cpp_num_part) 0 >> (PART_PRECISION / 2))
28 #define LOW_PART(num_part) (num_part & HALF_MASK)
29 #define HIGH_PART(num_part) (num_part >> (PART_PRECISION / 2))
33 const cpp_token
*token
; /* The token forming op (for diagnostics). */
34 cpp_num value
; /* The value logically "right" of op. */
35 source_location loc
; /* The location of this value. */
39 /* Some simple utility routines on double integers. */
40 #define num_zerop(num) ((num.low | num.high) == 0)
41 #define num_eq(num1, num2) (num1.low == num2.low && num1.high == num2.high)
42 static bool num_positive (cpp_num
, size_t);
43 static bool num_greater_eq (cpp_num
, cpp_num
, size_t);
44 static cpp_num
num_trim (cpp_num
, size_t);
45 static cpp_num
num_part_mul (cpp_num_part
, cpp_num_part
);
47 static cpp_num
num_unary_op (cpp_reader
*, cpp_num
, enum cpp_ttype
);
48 static cpp_num
num_binary_op (cpp_reader
*, cpp_num
, cpp_num
, enum cpp_ttype
);
49 static cpp_num
num_negate (cpp_num
, size_t);
50 static cpp_num
num_bitwise_op (cpp_reader
*, cpp_num
, cpp_num
, enum cpp_ttype
);
51 static cpp_num
num_inequality_op (cpp_reader
*, cpp_num
, cpp_num
,
53 static cpp_num
num_equality_op (cpp_reader
*, cpp_num
, cpp_num
,
55 static cpp_num
num_mul (cpp_reader
*, cpp_num
, cpp_num
);
56 static cpp_num
num_div_op (cpp_reader
*, cpp_num
, cpp_num
, enum cpp_ttype
);
57 static cpp_num
num_lshift (cpp_num
, size_t, size_t);
58 static cpp_num
num_rshift (cpp_num
, size_t, size_t);
60 static cpp_num
append_digit (cpp_num
, int, int, size_t);
61 static cpp_num
parse_defined (cpp_reader
*);
62 static cpp_num
eval_token (cpp_reader
*, const cpp_token
*);
63 static struct op
*reduce (cpp_reader
*, struct op
*, enum cpp_ttype
);
64 static unsigned int interpret_float_suffix (const uchar
*, size_t);
65 static unsigned int interpret_int_suffix (const uchar
*, size_t);
66 static void check_promotion (cpp_reader
*, const struct op
*);
68 /* Token type abuse to create unary plus and minus operators. */
69 #define CPP_UPLUS ((enum cpp_ttype) (CPP_LAST_CPP_OP + 1))
70 #define CPP_UMINUS ((enum cpp_ttype) (CPP_LAST_CPP_OP + 2))
72 /* With -O2, gcc appears to produce nice code, moving the error
73 message load and subsequent jump completely out of the main path. */
74 #define SYNTAX_ERROR(msgid) \
75 do { cpp_error (pfile, CPP_DL_ERROR, msgid); goto syntax_error; } while(0)
76 #define SYNTAX_ERROR2(msgid, arg) \
77 do { cpp_error (pfile, CPP_DL_ERROR, msgid, arg); goto syntax_error; } \
80 /* Subroutine of cpp_classify_number. S points to a float suffix of
81 length LEN, possibly zero. Returns 0 for an invalid suffix, or a
82 flag vector describing the suffix. */
84 interpret_float_suffix (const uchar
*s
, size_t len
)
90 f
= l
= w
= q
= i
= 0;
92 /* Process decimal float suffixes, which are two letters starting
93 with d or D. Order and case are significant. */
94 if (len
== 2 && (*s
== 'd' || *s
== 'D'))
96 bool uppercase
= (*s
== 'D');
99 case 'f': return (!uppercase
? (CPP_N_DFLOAT
| CPP_N_SMALL
): 0); break;
100 case 'F': return (uppercase
? (CPP_N_DFLOAT
| CPP_N_SMALL
) : 0); break;
101 case 'd': return (!uppercase
? (CPP_N_DFLOAT
| CPP_N_MEDIUM
): 0); break;
102 case 'D': return (uppercase
? (CPP_N_DFLOAT
| CPP_N_MEDIUM
) : 0); break;
103 case 'l': return (!uppercase
? (CPP_N_DFLOAT
| CPP_N_LARGE
) : 0); break;
104 case 'L': return (uppercase
? (CPP_N_DFLOAT
| CPP_N_LARGE
) : 0); break;
110 /* Recognize a fixed-point suffix. */
113 case 'k': case 'K': flags
= CPP_N_ACCUM
; break;
114 case 'r': case 'R': flags
= CPP_N_FRACT
; break;
118 /* Continue processing a fixed-point suffix. The suffix is case
119 insensitive except for ll or LL. Order is significant. */
126 if (*s
== 'u' || *s
== 'U')
128 flags
|= CPP_N_UNSIGNED
;
139 return flags
|= CPP_N_SMALL
;
143 return flags
|= CPP_N_MEDIUM
;
144 if (len
== 2 && s
[1] == 'l')
145 return flags
|= CPP_N_LARGE
;
149 return flags
|= CPP_N_MEDIUM
;
150 if (len
== 2 && s
[1] == 'L')
151 return flags
|= CPP_N_LARGE
;
156 /* Anything left at this point is invalid. */
160 /* In any remaining valid suffix, the case and order don't matter. */
164 case 'f': case 'F': f
++; break;
165 case 'l': case 'L': l
++; break;
166 case 'w': case 'W': w
++; break;
167 case 'q': case 'Q': q
++; break;
169 case 'j': case 'J': i
++; break;
174 if (f
+ l
+ w
+ q
> 1 || i
> 1)
177 return ((i
? CPP_N_IMAGINARY
: 0)
181 q
? CPP_N_MD_Q
: CPP_N_MEDIUM
));
184 /* Subroutine of cpp_classify_number. S points to an integer suffix
185 of length LEN, possibly zero. Returns 0 for an invalid suffix, or a
186 flag vector describing the suffix. */
188 interpret_int_suffix (const uchar
*s
, size_t len
)
197 case 'u': case 'U': u
++; break;
199 case 'j': case 'J': i
++; break;
200 case 'l': case 'L': l
++;
201 /* If there are two Ls, they must be adjacent and the same case. */
202 if (l
== 2 && s
[len
] != s
[len
+ 1])
209 if (l
> 2 || u
> 1 || i
> 1)
212 return ((i
? CPP_N_IMAGINARY
: 0)
213 | (u
? CPP_N_UNSIGNED
: 0)
214 | ((l
== 0) ? CPP_N_SMALL
215 : (l
== 1) ? CPP_N_MEDIUM
: CPP_N_LARGE
));
218 /* Categorize numeric constants according to their field (integer,
219 floating point, or invalid), radix (decimal, octal, hexadecimal),
220 and type suffixes. */
222 cpp_classify_number (cpp_reader
*pfile
, const cpp_token
*token
)
224 const uchar
*str
= token
->val
.str
.text
;
226 unsigned int max_digit
, result
, radix
;
227 enum {NOT_FLOAT
= 0, AFTER_POINT
, AFTER_EXPON
} float_flag
;
229 /* If the lexer has done its job, length one can only be a single
230 digit. Fast-path this very common case. */
231 if (token
->val
.str
.len
== 1)
232 return CPP_N_INTEGER
| CPP_N_SMALL
| CPP_N_DECIMAL
;
234 limit
= str
+ token
->val
.str
.len
;
235 float_flag
= NOT_FLOAT
;
239 /* First, interpret the radix. */
245 /* Require at least one hex digit to classify it as hex. */
246 if ((*str
== 'x' || *str
== 'X')
247 && (str
[1] == '.' || ISXDIGIT (str
[1])))
252 else if ((*str
== 'b' || *str
== 'B') && (str
[1] == '0' || str
[1] == '1'))
259 /* Now scan for a well-formed integer or float. */
262 unsigned int c
= *str
++;
264 if (ISDIGIT (c
) || (ISXDIGIT (c
) && radix
== 16))
272 if (float_flag
== NOT_FLOAT
)
273 float_flag
= AFTER_POINT
;
275 SYNTAX_ERROR ("too many decimal points in number");
277 else if ((radix
<= 10 && (c
== 'e' || c
== 'E'))
278 || (radix
== 16 && (c
== 'p' || c
== 'P')))
280 float_flag
= AFTER_EXPON
;
285 /* Start of suffix. */
291 /* The suffix may be for decimal fixed-point constants without exponent. */
292 if (radix
!= 16 && float_flag
== NOT_FLOAT
)
294 result
= interpret_float_suffix (str
, limit
- str
);
295 if ((result
& CPP_N_FRACT
) || (result
& CPP_N_ACCUM
))
297 result
|= CPP_N_FLOATING
;
298 /* We need to restore the radix to 10, if the radix is 8. */
302 if (CPP_PEDANTIC (pfile
))
303 cpp_error (pfile
, CPP_DL_PEDWARN
,
304 "fixed-point constants are a GCC extension");
311 if (float_flag
!= NOT_FLOAT
&& radix
== 8)
314 if (max_digit
>= radix
)
317 SYNTAX_ERROR2 ("invalid digit \"%c\" in binary constant", '0' + max_digit
);
319 SYNTAX_ERROR2 ("invalid digit \"%c\" in octal constant", '0' + max_digit
);
322 if (float_flag
!= NOT_FLOAT
)
326 cpp_error (pfile
, CPP_DL_ERROR
,
327 "invalid prefix \"0b\" for floating constant");
328 return CPP_N_INVALID
;
331 if (radix
== 16 && CPP_PEDANTIC (pfile
) && !CPP_OPTION (pfile
, c99
))
332 cpp_error (pfile
, CPP_DL_PEDWARN
,
333 "use of C99 hexadecimal floating constant");
335 if (float_flag
== AFTER_EXPON
)
337 if (*str
== '+' || *str
== '-')
340 /* Exponent is decimal, even if string is a hex float. */
342 SYNTAX_ERROR ("exponent has no digits");
346 while (ISDIGIT (*str
));
348 else if (radix
== 16)
349 SYNTAX_ERROR ("hexadecimal floating constants require an exponent");
351 result
= interpret_float_suffix (str
, limit
- str
);
354 cpp_error (pfile
, CPP_DL_ERROR
,
355 "invalid suffix \"%.*s\" on floating constant",
356 (int) (limit
- str
), str
);
357 return CPP_N_INVALID
;
360 /* Traditional C didn't accept any floating suffixes. */
362 && CPP_WTRADITIONAL (pfile
)
363 && ! cpp_sys_macro_p (pfile
))
364 cpp_error (pfile
, CPP_DL_WARNING
,
365 "traditional C rejects the \"%.*s\" suffix",
366 (int) (limit
- str
), str
);
368 /* Radix must be 10 for decimal floats. */
369 if ((result
& CPP_N_DFLOAT
) && radix
!= 10)
371 cpp_error (pfile
, CPP_DL_ERROR
,
372 "invalid suffix \"%.*s\" with hexadecimal floating constant",
373 (int) (limit
- str
), str
);
374 return CPP_N_INVALID
;
377 if ((result
& (CPP_N_FRACT
| CPP_N_ACCUM
)) && CPP_PEDANTIC (pfile
))
378 cpp_error (pfile
, CPP_DL_PEDWARN
,
379 "fixed-point constants are a GCC extension");
381 if ((result
& CPP_N_DFLOAT
) && CPP_PEDANTIC (pfile
))
382 cpp_error (pfile
, CPP_DL_PEDWARN
,
383 "decimal float constants are a GCC extension");
385 result
|= CPP_N_FLOATING
;
389 result
= interpret_int_suffix (str
, limit
- str
);
392 cpp_error (pfile
, CPP_DL_ERROR
,
393 "invalid suffix \"%.*s\" on integer constant",
394 (int) (limit
- str
), str
);
395 return CPP_N_INVALID
;
398 /* Traditional C only accepted the 'L' suffix.
399 Suppress warning about 'LL' with -Wno-long-long. */
400 if (CPP_WTRADITIONAL (pfile
) && ! cpp_sys_macro_p (pfile
))
402 int u_or_i
= (result
& (CPP_N_UNSIGNED
|CPP_N_IMAGINARY
));
403 int large
= (result
& CPP_N_WIDTH
) == CPP_N_LARGE
;
405 if (u_or_i
|| (large
&& CPP_OPTION (pfile
, warn_long_long
)))
406 cpp_error (pfile
, CPP_DL_WARNING
,
407 "traditional C rejects the \"%.*s\" suffix",
408 (int) (limit
- str
), str
);
411 if ((result
& CPP_N_WIDTH
) == CPP_N_LARGE
412 && ! CPP_OPTION (pfile
, c99
)
413 && CPP_OPTION (pfile
, warn_long_long
))
414 cpp_error (pfile
, CPP_DL_PEDWARN
,
415 "use of C99 long long integer constant");
417 result
|= CPP_N_INTEGER
;
421 if ((result
& CPP_N_IMAGINARY
) && CPP_PEDANTIC (pfile
))
422 cpp_error (pfile
, CPP_DL_PEDWARN
,
423 "imaginary constants are a GCC extension");
424 if (radix
== 2 && CPP_PEDANTIC (pfile
))
425 cpp_error (pfile
, CPP_DL_PEDWARN
,
426 "binary constants are a GCC extension");
429 result
|= CPP_N_DECIMAL
;
430 else if (radix
== 16)
433 result
|= CPP_N_BINARY
;
435 result
|= CPP_N_OCTAL
;
440 return CPP_N_INVALID
;
443 /* cpp_interpret_integer converts an integer constant into a cpp_num,
444 of precision options->precision.
446 We do not provide any interface for decimal->float conversion,
447 because the preprocessor doesn't need it and we don't want to
448 drag in GCC's floating point emulator. */
450 cpp_interpret_integer (cpp_reader
*pfile
, const cpp_token
*token
,
453 const uchar
*p
, *end
;
458 result
.unsignedp
= !!(type
& CPP_N_UNSIGNED
);
459 result
.overflow
= false;
461 p
= token
->val
.str
.text
;
462 end
= p
+ token
->val
.str
.len
;
464 /* Common case of a single digit. */
465 if (token
->val
.str
.len
== 1)
466 result
.low
= p
[0] - '0';
470 size_t precision
= CPP_OPTION (pfile
, precision
);
471 unsigned int base
= 10, c
= 0;
472 bool overflow
= false;
474 if ((type
& CPP_N_RADIX
) == CPP_N_OCTAL
)
479 else if ((type
& CPP_N_RADIX
) == CPP_N_HEX
)
484 else if ((type
& CPP_N_RADIX
) == CPP_N_BINARY
)
490 /* We can add a digit to numbers strictly less than this without
491 needing the precision and slowness of double integers. */
492 max
= ~(cpp_num_part
) 0;
493 if (precision
< PART_PRECISION
)
494 max
>>= PART_PRECISION
- precision
;
495 max
= (max
- base
+ 1) / base
+ 1;
501 if (ISDIGIT (c
) || (base
== 16 && ISXDIGIT (c
)))
506 /* Strict inequality for when max is set to zero. */
507 if (result
.low
< max
)
508 result
.low
= result
.low
* base
+ c
;
511 result
= append_digit (result
, c
, base
, precision
);
512 overflow
|= result
.overflow
;
518 cpp_error (pfile
, CPP_DL_PEDWARN
,
519 "integer constant is too large for its type");
520 /* If too big to be signed, consider it unsigned. Only warn for
521 decimal numbers. Traditional numbers were always signed (but
522 we still honor an explicit U suffix); but we only have
523 traditional semantics in directives. */
524 else if (!result
.unsignedp
525 && !(CPP_OPTION (pfile
, traditional
)
526 && pfile
->state
.in_directive
)
527 && !num_positive (result
, precision
))
530 cpp_error (pfile
, CPP_DL_WARNING
,
531 "integer constant is so large that it is unsigned");
532 result
.unsignedp
= true;
539 /* Append DIGIT to NUM, a number of PRECISION bits being read in base BASE. */
541 append_digit (cpp_num num
, int digit
, int base
, size_t precision
)
546 cpp_num_part add_high
, add_low
;
548 /* Multiply by 2, 8 or 16. Catching this overflow here means we don't
549 need to worry about add_high overflowing. */
563 overflow
= !!(num
.high
>> (PART_PRECISION
- shift
));
564 result
.high
= num
.high
<< shift
;
565 result
.low
= num
.low
<< shift
;
566 result
.high
|= num
.low
>> (PART_PRECISION
- shift
);
567 result
.unsignedp
= num
.unsignedp
;
571 add_low
= num
.low
<< 1;
572 add_high
= (num
.high
<< 1) + (num
.low
>> (PART_PRECISION
- 1));
575 add_high
= add_low
= 0;
577 if (add_low
+ digit
< add_low
)
581 if (result
.low
+ add_low
< result
.low
)
583 if (result
.high
+ add_high
< result
.high
)
586 result
.low
+= add_low
;
587 result
.high
+= add_high
;
588 result
.overflow
= overflow
;
590 /* The above code catches overflow of a cpp_num type. This catches
591 overflow of the (possibly shorter) target precision. */
592 num
.low
= result
.low
;
593 num
.high
= result
.high
;
594 result
= num_trim (result
, precision
);
595 if (!num_eq (result
, num
))
596 result
.overflow
= true;
601 /* Handle meeting "defined" in a preprocessor expression. */
603 parse_defined (cpp_reader
*pfile
)
607 cpp_hashnode
*node
= 0;
608 const cpp_token
*token
;
609 cpp_context
*initial_context
= pfile
->context
;
611 /* Don't expand macros. */
612 pfile
->state
.prevent_expansion
++;
614 token
= cpp_get_token (pfile
);
615 if (token
->type
== CPP_OPEN_PAREN
)
618 token
= cpp_get_token (pfile
);
621 if (token
->type
== CPP_NAME
)
623 node
= token
->val
.node
;
624 if (paren
&& cpp_get_token (pfile
)->type
!= CPP_CLOSE_PAREN
)
626 cpp_error (pfile
, CPP_DL_ERROR
, "missing ')' after \"defined\"");
632 cpp_error (pfile
, CPP_DL_ERROR
,
633 "operator \"defined\" requires an identifier");
634 if (token
->flags
& NAMED_OP
)
639 op
.type
= token
->type
;
640 cpp_error (pfile
, CPP_DL_ERROR
,
641 "(\"%s\" is an alternative token for \"%s\" in C++)",
642 cpp_token_as_text (pfile
, token
),
643 cpp_token_as_text (pfile
, &op
));
649 if (pfile
->context
!= initial_context
&& CPP_PEDANTIC (pfile
))
650 cpp_error (pfile
, CPP_DL_WARNING
,
651 "this use of \"defined\" may not be portable");
653 _cpp_mark_macro_used (node
);
654 if (!(node
->flags
& NODE_USED
))
656 node
->flags
|= NODE_USED
;
657 if (node
->type
== NT_MACRO
)
659 if (pfile
->cb
.used_define
)
660 pfile
->cb
.used_define (pfile
, pfile
->directive_line
, node
);
664 if (pfile
->cb
.used_undef
)
665 pfile
->cb
.used_undef (pfile
, pfile
->directive_line
, node
);
669 /* A possible controlling macro of the form #if !defined ().
670 _cpp_parse_expr checks there was no other junk on the line. */
671 pfile
->mi_ind_cmacro
= node
;
674 pfile
->state
.prevent_expansion
--;
676 result
.unsignedp
= false;
678 result
.overflow
= false;
679 result
.low
= node
&& node
->type
== NT_MACRO
;
683 /* Convert a token into a CPP_NUMBER (an interpreted preprocessing
684 number or character constant, or the result of the "defined" or "#"
687 eval_token (cpp_reader
*pfile
, const cpp_token
*token
)
693 result
.unsignedp
= false;
694 result
.overflow
= false;
699 temp
= cpp_classify_number (pfile
, token
);
700 switch (temp
& CPP_N_CATEGORY
)
703 cpp_error (pfile
, CPP_DL_ERROR
,
704 "floating constant in preprocessor expression");
707 if (!(temp
& CPP_N_IMAGINARY
))
708 return cpp_interpret_integer (pfile
, token
, temp
);
709 cpp_error (pfile
, CPP_DL_ERROR
,
710 "imaginary number in preprocessor expression");
714 /* Error already issued. */
717 result
.high
= result
.low
= 0;
725 cppchar_t cc
= cpp_interpret_charconst (pfile
, token
,
730 /* Sign-extend the result if necessary. */
731 if (!unsignedp
&& (cppchar_signed_t
) cc
< 0)
733 if (PART_PRECISION
> BITS_PER_CPPCHAR_T
)
734 result
.low
|= ~(~(cpp_num_part
) 0
735 >> (PART_PRECISION
- BITS_PER_CPPCHAR_T
));
736 result
.high
= ~(cpp_num_part
) 0;
737 result
= num_trim (result
, CPP_OPTION (pfile
, precision
));
743 if (token
->val
.node
== pfile
->spec_nodes
.n_defined
)
744 return parse_defined (pfile
);
745 else if (CPP_OPTION (pfile
, cplusplus
)
746 && (token
->val
.node
== pfile
->spec_nodes
.n_true
747 || token
->val
.node
== pfile
->spec_nodes
.n_false
))
750 result
.low
= (token
->val
.node
== pfile
->spec_nodes
.n_true
);
756 if (CPP_OPTION (pfile
, warn_undef
) && !pfile
->state
.skip_eval
)
757 cpp_error (pfile
, CPP_DL_WARNING
, "\"%s\" is not defined",
758 NODE_NAME (token
->val
.node
));
763 if (!pfile
->state
.skipping
)
765 /* A pedantic warning takes precedence over a deprecated
767 if (CPP_PEDANTIC (pfile
))
768 cpp_error (pfile
, CPP_DL_PEDWARN
,
769 "assertions are a GCC extension");
770 else if (CPP_OPTION (pfile
, warn_deprecated
))
771 cpp_error (pfile
, CPP_DL_WARNING
,
772 "assertions are a deprecated extension");
774 _cpp_test_assertion (pfile
, &temp
);
783 result
.unsignedp
= !!unsignedp
;
787 /* Operator precedence and flags table.
789 After an operator is returned from the lexer, if it has priority less
790 than the operator on the top of the stack, we reduce the stack by one
791 operator and repeat the test. Since equal priorities do not reduce,
792 this is naturally right-associative.
794 We handle left-associative operators by decrementing the priority of
795 just-lexed operators by one, but retaining the priority of operators
796 already on the stack.
798 The remaining cases are '(' and ')'. We handle '(' by skipping the
799 reduction phase completely. ')' is given lower priority than
800 everything else, including '(', effectively forcing a reduction of the
801 parenthesized expression. If there is a matching '(', the routine
802 reduce() exits immediately. If the normal exit route sees a ')', then
803 there cannot have been a matching '(' and an error message is output.
805 The parser assumes all shifted operators require a left operand unless
806 the flag NO_L_OPERAND is set. These semantics are automatic; any
807 extra semantics need to be handled with operator-specific code. */
809 /* Flags. If CHECK_PROMOTION, we warn if the effective sign of an
810 operand changes because of integer promotions. */
811 #define NO_L_OPERAND (1 << 0)
812 #define LEFT_ASSOC (1 << 1)
813 #define CHECK_PROMOTION (1 << 2)
815 /* Operator to priority map. Must be in the same order as the first
816 N entries of enum cpp_ttype. */
817 static const struct cpp_operator
823 /* EQ */ {0, 0}, /* Shouldn't happen. */
824 /* NOT */ {16, NO_L_OPERAND
},
825 /* GREATER */ {12, LEFT_ASSOC
| CHECK_PROMOTION
},
826 /* LESS */ {12, LEFT_ASSOC
| CHECK_PROMOTION
},
827 /* PLUS */ {14, LEFT_ASSOC
| CHECK_PROMOTION
},
828 /* MINUS */ {14, LEFT_ASSOC
| CHECK_PROMOTION
},
829 /* MULT */ {15, LEFT_ASSOC
| CHECK_PROMOTION
},
830 /* DIV */ {15, LEFT_ASSOC
| CHECK_PROMOTION
},
831 /* MOD */ {15, LEFT_ASSOC
| CHECK_PROMOTION
},
832 /* AND */ {9, LEFT_ASSOC
| CHECK_PROMOTION
},
833 /* OR */ {7, LEFT_ASSOC
| CHECK_PROMOTION
},
834 /* XOR */ {8, LEFT_ASSOC
| CHECK_PROMOTION
},
835 /* RSHIFT */ {13, LEFT_ASSOC
},
836 /* LSHIFT */ {13, LEFT_ASSOC
},
838 /* COMPL */ {16, NO_L_OPERAND
},
839 /* AND_AND */ {6, LEFT_ASSOC
},
840 /* OR_OR */ {5, LEFT_ASSOC
},
841 /* Note that QUERY, COLON, and COMMA must have the same precedence.
842 However, there are some special cases for these in reduce(). */
844 /* COLON */ {4, LEFT_ASSOC
| CHECK_PROMOTION
},
845 /* COMMA */ {4, LEFT_ASSOC
},
846 /* OPEN_PAREN */ {1, NO_L_OPERAND
},
847 /* CLOSE_PAREN */ {0, 0},
849 /* EQ_EQ */ {11, LEFT_ASSOC
},
850 /* NOT_EQ */ {11, LEFT_ASSOC
},
851 /* GREATER_EQ */ {12, LEFT_ASSOC
| CHECK_PROMOTION
},
852 /* LESS_EQ */ {12, LEFT_ASSOC
| CHECK_PROMOTION
},
853 /* UPLUS */ {16, NO_L_OPERAND
},
854 /* UMINUS */ {16, NO_L_OPERAND
}
857 /* Parse and evaluate a C expression, reading from PFILE.
858 Returns the truth value of the expression.
860 The implementation is an operator precedence parser, i.e. a
861 bottom-up parser, using a stack for not-yet-reduced tokens.
863 The stack base is op_stack, and the current stack pointer is 'top'.
864 There is a stack element for each operator (only), and the most
865 recently pushed operator is 'top->op'. An operand (value) is
866 stored in the 'value' field of the stack element of the operator
869 _cpp_parse_expr (cpp_reader
*pfile
, bool is_if
)
871 struct op
*top
= pfile
->op_stack
;
872 unsigned int lex_count
;
873 bool saw_leading_not
, want_value
= true;
875 pfile
->state
.skip_eval
= 0;
877 /* Set up detection of #if ! defined(). */
878 pfile
->mi_ind_cmacro
= 0;
879 saw_leading_not
= false;
882 /* Lowest priority operator prevents further reductions. */
890 op
.token
= cpp_get_token (pfile
);
891 op
.op
= op
.token
->type
;
892 op
.loc
= op
.token
->src_loc
;
896 /* These tokens convert into values. */
905 SYNTAX_ERROR2 ("missing binary operator before token \"%s\"",
906 cpp_token_as_text (pfile
, op
.token
));
908 top
->value
= eval_token (pfile
, op
.token
);
912 saw_leading_not
= lex_count
== 1;
924 if ((int) op
.op
<= (int) CPP_EQ
|| (int) op
.op
>= (int) CPP_PLUS_EQ
)
925 SYNTAX_ERROR2 ("token \"%s\" is not valid in preprocessor expressions",
926 cpp_token_as_text (pfile
, op
.token
));
930 /* Check we have a value or operator as appropriate. */
931 if (optab
[op
.op
].flags
& NO_L_OPERAND
)
934 SYNTAX_ERROR2 ("missing binary operator before token \"%s\"",
935 cpp_token_as_text (pfile
, op
.token
));
939 /* We want a number (or expression) and haven't got one.
940 Try to emit a specific diagnostic. */
941 if (op
.op
== CPP_CLOSE_PAREN
&& top
->op
== CPP_OPEN_PAREN
)
942 SYNTAX_ERROR ("missing expression between '(' and ')'");
944 if (op
.op
== CPP_EOF
&& top
->op
== CPP_EOF
)
945 SYNTAX_ERROR2 ("%s with no expression", is_if
? "#if" : "#elif");
947 if (top
->op
!= CPP_EOF
&& top
->op
!= CPP_OPEN_PAREN
)
948 SYNTAX_ERROR2 ("operator '%s' has no right operand",
949 cpp_token_as_text (pfile
, top
->token
));
950 else if (op
.op
== CPP_CLOSE_PAREN
|| op
.op
== CPP_EOF
)
951 /* Complain about missing paren during reduction. */;
953 SYNTAX_ERROR2 ("operator '%s' has no left operand",
954 cpp_token_as_text (pfile
, op
.token
));
957 top
= reduce (pfile
, top
, op
.op
);
961 if (op
.op
== CPP_EOF
)
966 case CPP_CLOSE_PAREN
:
969 if (!num_zerop (top
->value
))
970 pfile
->state
.skip_eval
++;
974 if (num_zerop (top
->value
))
975 pfile
->state
.skip_eval
++;
978 if (top
->op
!= CPP_QUERY
)
979 SYNTAX_ERROR (" ':' without preceding '?'");
980 if (!num_zerop (top
[-1].value
)) /* Was '?' condition true? */
981 pfile
->state
.skip_eval
++;
983 pfile
->state
.skip_eval
--;
990 /* Check for and handle stack overflow. */
991 if (++top
== pfile
->op_limit
)
992 top
= _cpp_expand_op_stack (pfile
);
995 top
->token
= op
.token
;
996 top
->loc
= op
.token
->src_loc
;
999 /* The controlling macro expression is only valid if we called lex 3
1000 times: <!> <defined expression> and <EOF>. push_conditional ()
1001 checks that we are at top-of-file. */
1002 if (pfile
->mi_ind_cmacro
&& !(saw_leading_not
&& lex_count
== 3))
1003 pfile
->mi_ind_cmacro
= 0;
1005 if (top
!= pfile
->op_stack
)
1007 cpp_error (pfile
, CPP_DL_ICE
, "unbalanced stack in %s",
1008 is_if
? "#if" : "#elif");
1010 return false; /* Return false on syntax error. */
1013 return !num_zerop (top
->value
);
1016 /* Reduce the operator / value stack if possible, in preparation for
1017 pushing operator OP. Returns NULL on error, otherwise the top of
1020 reduce (cpp_reader
*pfile
, struct op
*top
, enum cpp_ttype op
)
1024 if (top
->op
<= CPP_EQ
|| top
->op
> CPP_LAST_CPP_OP
+ 2)
1027 cpp_error (pfile
, CPP_DL_ICE
, "impossible operator '%u'", top
->op
);
1031 if (op
== CPP_OPEN_PAREN
)
1034 /* Decrement the priority of left-associative operators to force a
1035 reduction with operators of otherwise equal priority. */
1036 prio
= optab
[op
].prio
- ((optab
[op
].flags
& LEFT_ASSOC
) != 0);
1037 while (prio
< optab
[top
->op
].prio
)
1039 if (CPP_OPTION (pfile
, warn_num_sign_change
)
1040 && optab
[top
->op
].flags
& CHECK_PROMOTION
)
1041 check_promotion (pfile
, top
);
1049 top
[-1].value
= num_unary_op (pfile
, top
->value
, top
->op
);
1050 top
[-1].loc
= top
->loc
;
1058 top
[-1].value
= num_binary_op (pfile
, top
[-1].value
,
1059 top
->value
, top
->op
);
1060 top
[-1].loc
= top
->loc
;
1065 case CPP_GREATER_EQ
:
1068 = num_inequality_op (pfile
, top
[-1].value
, top
->value
, top
->op
);
1069 top
[-1].loc
= top
->loc
;
1075 = num_equality_op (pfile
, top
[-1].value
, top
->value
, top
->op
);
1076 top
[-1].loc
= top
->loc
;
1083 = num_bitwise_op (pfile
, top
[-1].value
, top
->value
, top
->op
);
1084 top
[-1].loc
= top
->loc
;
1088 top
[-1].value
= num_mul (pfile
, top
[-1].value
, top
->value
);
1089 top
[-1].loc
= top
->loc
;
1094 top
[-1].value
= num_div_op (pfile
, top
[-1].value
,
1095 top
->value
, top
->op
);
1096 top
[-1].loc
= top
->loc
;
1101 if (!num_zerop (top
->value
))
1102 pfile
->state
.skip_eval
--;
1103 top
->value
.low
= (!num_zerop (top
->value
)
1104 || !num_zerop (top
[1].value
));
1105 top
->value
.high
= 0;
1106 top
->value
.unsignedp
= false;
1107 top
->value
.overflow
= false;
1108 top
->loc
= top
[1].loc
;
1113 if (num_zerop (top
->value
))
1114 pfile
->state
.skip_eval
--;
1115 top
->value
.low
= (!num_zerop (top
->value
)
1116 && !num_zerop (top
[1].value
));
1117 top
->value
.high
= 0;
1118 top
->value
.unsignedp
= false;
1119 top
->value
.overflow
= false;
1120 top
->loc
= top
[1].loc
;
1123 case CPP_OPEN_PAREN
:
1124 if (op
!= CPP_CLOSE_PAREN
)
1126 cpp_error_with_line (pfile
, CPP_DL_ERROR
,
1127 top
->token
->src_loc
,
1128 0, "missing ')' in expression");
1132 top
->value
= top
[1].value
;
1133 top
->loc
= top
[1].loc
;
1138 if (!num_zerop (top
->value
))
1140 pfile
->state
.skip_eval
--;
1141 top
->value
= top
[1].value
;
1142 top
->loc
= top
[1].loc
;
1146 top
->value
= top
[2].value
;
1147 top
->loc
= top
[2].loc
;
1149 top
->value
.unsignedp
= (top
[1].value
.unsignedp
1150 || top
[2].value
.unsignedp
);
1154 /* COMMA and COLON should not reduce a QUERY operator. */
1155 if (op
== CPP_COMMA
|| op
== CPP_COLON
)
1157 cpp_error (pfile
, CPP_DL_ERROR
, "'?' without following ':'");
1165 if (top
->value
.overflow
&& !pfile
->state
.skip_eval
)
1166 cpp_error (pfile
, CPP_DL_PEDWARN
,
1167 "integer overflow in preprocessor expression");
1170 if (op
== CPP_CLOSE_PAREN
)
1172 cpp_error (pfile
, CPP_DL_ERROR
, "missing '(' in expression");
1179 /* Returns the position of the old top of stack after expansion. */
1181 _cpp_expand_op_stack (cpp_reader
*pfile
)
1183 size_t old_size
= (size_t) (pfile
->op_limit
- pfile
->op_stack
);
1184 size_t new_size
= old_size
* 2 + 20;
1186 pfile
->op_stack
= XRESIZEVEC (struct op
, pfile
->op_stack
, new_size
);
1187 pfile
->op_limit
= pfile
->op_stack
+ new_size
;
1189 return pfile
->op_stack
+ old_size
;
1192 /* Emits a warning if the effective sign of either operand of OP
1193 changes because of integer promotions. */
1195 check_promotion (cpp_reader
*pfile
, const struct op
*op
)
1197 if (op
->value
.unsignedp
== op
[-1].value
.unsignedp
)
1200 if (op
->value
.unsignedp
)
1202 if (!num_positive (op
[-1].value
, CPP_OPTION (pfile
, precision
)))
1203 cpp_error_with_line (pfile
, CPP_DL_WARNING
, op
[-1].loc
, 0,
1204 "the left operand of \"%s\" changes sign when promoted",
1205 cpp_token_as_text (pfile
, op
->token
));
1207 else if (!num_positive (op
->value
, CPP_OPTION (pfile
, precision
)))
1208 cpp_error_with_line (pfile
, CPP_DL_WARNING
, op
->loc
, 0,
1209 "the right operand of \"%s\" changes sign when promoted",
1210 cpp_token_as_text (pfile
, op
->token
));
1213 /* Clears the unused high order bits of the number pointed to by PNUM. */
1215 num_trim (cpp_num num
, size_t precision
)
1217 if (precision
> PART_PRECISION
)
1219 precision
-= PART_PRECISION
;
1220 if (precision
< PART_PRECISION
)
1221 num
.high
&= ((cpp_num_part
) 1 << precision
) - 1;
1225 if (precision
< PART_PRECISION
)
1226 num
.low
&= ((cpp_num_part
) 1 << precision
) - 1;
1233 /* True iff A (presumed signed) >= 0. */
1235 num_positive (cpp_num num
, size_t precision
)
1237 if (precision
> PART_PRECISION
)
1239 precision
-= PART_PRECISION
;
1240 return (num
.high
& (cpp_num_part
) 1 << (precision
- 1)) == 0;
1243 return (num
.low
& (cpp_num_part
) 1 << (precision
- 1)) == 0;
1246 /* Sign extend a number, with PRECISION significant bits and all
1247 others assumed clear, to fill out a cpp_num structure. */
1249 cpp_num_sign_extend (cpp_num num
, size_t precision
)
1253 if (precision
> PART_PRECISION
)
1255 precision
-= PART_PRECISION
;
1256 if (precision
< PART_PRECISION
1257 && (num
.high
& (cpp_num_part
) 1 << (precision
- 1)))
1258 num
.high
|= ~(~(cpp_num_part
) 0 >> (PART_PRECISION
- precision
));
1260 else if (num
.low
& (cpp_num_part
) 1 << (precision
- 1))
1262 if (precision
< PART_PRECISION
)
1263 num
.low
|= ~(~(cpp_num_part
) 0 >> (PART_PRECISION
- precision
));
1264 num
.high
= ~(cpp_num_part
) 0;
1271 /* Returns the negative of NUM. */
1273 num_negate (cpp_num num
, size_t precision
)
1278 num
.high
= ~num
.high
;
1282 num
= num_trim (num
, precision
);
1283 num
.overflow
= (!num
.unsignedp
&& num_eq (num
, copy
) && !num_zerop (num
));
1288 /* Returns true if A >= B. */
1290 num_greater_eq (cpp_num pa
, cpp_num pb
, size_t precision
)
1294 unsignedp
= pa
.unsignedp
|| pb
.unsignedp
;
1298 /* Both numbers have signed type. If they are of different
1299 sign, the answer is the sign of A. */
1300 unsignedp
= num_positive (pa
, precision
);
1302 if (unsignedp
!= num_positive (pb
, precision
))
1305 /* Otherwise we can do an unsigned comparison. */
1308 return (pa
.high
> pb
.high
) || (pa
.high
== pb
.high
&& pa
.low
>= pb
.low
);
1311 /* Returns LHS OP RHS, where OP is a bit-wise operation. */
1313 num_bitwise_op (cpp_reader
*pfile ATTRIBUTE_UNUSED
,
1314 cpp_num lhs
, cpp_num rhs
, enum cpp_ttype op
)
1316 lhs
.overflow
= false;
1317 lhs
.unsignedp
= lhs
.unsignedp
|| rhs
.unsignedp
;
1319 /* As excess precision is zeroed, there is no need to num_trim () as
1320 these operations cannot introduce a set bit there. */
1324 lhs
.high
&= rhs
.high
;
1326 else if (op
== CPP_OR
)
1329 lhs
.high
|= rhs
.high
;
1334 lhs
.high
^= rhs
.high
;
1340 /* Returns LHS OP RHS, where OP is an inequality. */
1342 num_inequality_op (cpp_reader
*pfile
, cpp_num lhs
, cpp_num rhs
,
1345 bool gte
= num_greater_eq (lhs
, rhs
, CPP_OPTION (pfile
, precision
));
1347 if (op
== CPP_GREATER_EQ
)
1349 else if (op
== CPP_LESS
)
1351 else if (op
== CPP_GREATER
)
1352 lhs
.low
= gte
&& !num_eq (lhs
, rhs
);
1353 else /* CPP_LESS_EQ. */
1354 lhs
.low
= !gte
|| num_eq (lhs
, rhs
);
1357 lhs
.overflow
= false;
1358 lhs
.unsignedp
= false;
1362 /* Returns LHS OP RHS, where OP is == or !=. */
1364 num_equality_op (cpp_reader
*pfile ATTRIBUTE_UNUSED
,
1365 cpp_num lhs
, cpp_num rhs
, enum cpp_ttype op
)
1367 /* Work around a 3.0.4 bug; see PR 6950. */
1368 bool eq
= num_eq (lhs
, rhs
);
1369 if (op
== CPP_NOT_EQ
)
1373 lhs
.overflow
= false;
1374 lhs
.unsignedp
= false;
1378 /* Shift NUM, of width PRECISION, right by N bits. */
1380 num_rshift (cpp_num num
, size_t precision
, size_t n
)
1382 cpp_num_part sign_mask
;
1383 bool x
= num_positive (num
, precision
);
1385 if (num
.unsignedp
|| x
)
1388 sign_mask
= ~(cpp_num_part
) 0;
1391 num
.high
= num
.low
= sign_mask
;
1395 if (precision
< PART_PRECISION
)
1396 num
.high
= sign_mask
, num
.low
|= sign_mask
<< precision
;
1397 else if (precision
< 2 * PART_PRECISION
)
1398 num
.high
|= sign_mask
<< (precision
- PART_PRECISION
);
1400 if (n
>= PART_PRECISION
)
1402 n
-= PART_PRECISION
;
1404 num
.high
= sign_mask
;
1409 num
.low
= (num
.low
>> n
) | (num
.high
<< (PART_PRECISION
- n
));
1410 num
.high
= (num
.high
>> n
) | (sign_mask
<< (PART_PRECISION
- n
));
1414 num
= num_trim (num
, precision
);
1415 num
.overflow
= false;
1419 /* Shift NUM, of width PRECISION, left by N bits. */
1421 num_lshift (cpp_num num
, size_t precision
, size_t n
)
1425 num
.overflow
= !num
.unsignedp
&& !num_zerop (num
);
1426 num
.high
= num
.low
= 0;
1430 cpp_num orig
, maybe_orig
;
1434 if (m
>= PART_PRECISION
)
1436 m
-= PART_PRECISION
;
1442 num
.high
= (num
.high
<< m
) | (num
.low
>> (PART_PRECISION
- m
));
1445 num
= num_trim (num
, precision
);
1448 num
.overflow
= false;
1451 maybe_orig
= num_rshift (num
, precision
, n
);
1452 num
.overflow
= !num_eq (orig
, maybe_orig
);
1459 /* The four unary operators: +, -, ! and ~. */
1461 num_unary_op (cpp_reader
*pfile
, cpp_num num
, enum cpp_ttype op
)
1466 if (CPP_WTRADITIONAL (pfile
) && !pfile
->state
.skip_eval
)
1467 cpp_error (pfile
, CPP_DL_WARNING
,
1468 "traditional C rejects the unary plus operator");
1469 num
.overflow
= false;
1473 num
= num_negate (num
, CPP_OPTION (pfile
, precision
));
1477 num
.high
= ~num
.high
;
1479 num
= num_trim (num
, CPP_OPTION (pfile
, precision
));
1480 num
.overflow
= false;
1483 default: /* case CPP_NOT: */
1484 num
.low
= num_zerop (num
);
1486 num
.overflow
= false;
1487 num
.unsignedp
= false;
1494 /* The various binary operators. */
1496 num_binary_op (cpp_reader
*pfile
, cpp_num lhs
, cpp_num rhs
, enum cpp_ttype op
)
1499 size_t precision
= CPP_OPTION (pfile
, precision
);
1507 if (!rhs
.unsignedp
&& !num_positive (rhs
, precision
))
1509 /* A negative shift is a positive shift the other way. */
1510 if (op
== CPP_LSHIFT
)
1514 rhs
= num_negate (rhs
, precision
);
1517 n
= ~0; /* Maximal. */
1520 if (op
== CPP_LSHIFT
)
1521 lhs
= num_lshift (lhs
, precision
, n
);
1523 lhs
= num_rshift (lhs
, precision
, n
);
1528 rhs
= num_negate (rhs
, precision
);
1530 result
.low
= lhs
.low
+ rhs
.low
;
1531 result
.high
= lhs
.high
+ rhs
.high
;
1532 if (result
.low
< lhs
.low
)
1534 result
.unsignedp
= lhs
.unsignedp
|| rhs
.unsignedp
;
1535 result
.overflow
= false;
1537 result
= num_trim (result
, precision
);
1538 if (!result
.unsignedp
)
1540 bool lhsp
= num_positive (lhs
, precision
);
1541 result
.overflow
= (lhsp
== num_positive (rhs
, precision
)
1542 && lhsp
!= num_positive (result
, precision
));
1547 default: /* case CPP_COMMA: */
1548 if (CPP_PEDANTIC (pfile
) && (!CPP_OPTION (pfile
, c99
)
1549 || !pfile
->state
.skip_eval
))
1550 cpp_error (pfile
, CPP_DL_PEDWARN
,
1551 "comma operator in operand of #if");
1559 /* Multiplies two unsigned cpp_num_parts to give a cpp_num. This
1562 num_part_mul (cpp_num_part lhs
, cpp_num_part rhs
)
1565 cpp_num_part middle
[2], temp
;
1567 result
.low
= LOW_PART (lhs
) * LOW_PART (rhs
);
1568 result
.high
= HIGH_PART (lhs
) * HIGH_PART (rhs
);
1570 middle
[0] = LOW_PART (lhs
) * HIGH_PART (rhs
);
1571 middle
[1] = HIGH_PART (lhs
) * LOW_PART (rhs
);
1574 result
.low
+= LOW_PART (middle
[0]) << (PART_PRECISION
/ 2);
1575 if (result
.low
< temp
)
1579 result
.low
+= LOW_PART (middle
[1]) << (PART_PRECISION
/ 2);
1580 if (result
.low
< temp
)
1583 result
.high
+= HIGH_PART (middle
[0]);
1584 result
.high
+= HIGH_PART (middle
[1]);
1585 result
.unsignedp
= true;
1586 result
.overflow
= false;
1591 /* Multiply two preprocessing numbers. */
1593 num_mul (cpp_reader
*pfile
, cpp_num lhs
, cpp_num rhs
)
1595 cpp_num result
, temp
;
1596 bool unsignedp
= lhs
.unsignedp
|| rhs
.unsignedp
;
1597 bool overflow
, negate
= false;
1598 size_t precision
= CPP_OPTION (pfile
, precision
);
1600 /* Prepare for unsigned multiplication. */
1603 if (!num_positive (lhs
, precision
))
1604 negate
= !negate
, lhs
= num_negate (lhs
, precision
);
1605 if (!num_positive (rhs
, precision
))
1606 negate
= !negate
, rhs
= num_negate (rhs
, precision
);
1609 overflow
= lhs
.high
&& rhs
.high
;
1610 result
= num_part_mul (lhs
.low
, rhs
.low
);
1612 temp
= num_part_mul (lhs
.high
, rhs
.low
);
1613 result
.high
+= temp
.low
;
1617 temp
= num_part_mul (lhs
.low
, rhs
.high
);
1618 result
.high
+= temp
.low
;
1622 temp
.low
= result
.low
, temp
.high
= result
.high
;
1623 result
= num_trim (result
, precision
);
1624 if (!num_eq (result
, temp
))
1628 result
= num_negate (result
, precision
);
1631 result
.overflow
= false;
1633 result
.overflow
= overflow
|| (num_positive (result
, precision
) ^ !negate
1634 && !num_zerop (result
));
1635 result
.unsignedp
= unsignedp
;
1640 /* Divide two preprocessing numbers, returning the answer or the
1641 remainder depending upon OP. */
1643 num_div_op (cpp_reader
*pfile
, cpp_num lhs
, cpp_num rhs
, enum cpp_ttype op
)
1645 cpp_num result
, sub
;
1647 bool unsignedp
= lhs
.unsignedp
|| rhs
.unsignedp
;
1648 bool negate
= false, lhs_neg
= false;
1649 size_t i
, precision
= CPP_OPTION (pfile
, precision
);
1651 /* Prepare for unsigned division. */
1654 if (!num_positive (lhs
, precision
))
1655 negate
= !negate
, lhs_neg
= true, lhs
= num_negate (lhs
, precision
);
1656 if (!num_positive (rhs
, precision
))
1657 negate
= !negate
, rhs
= num_negate (rhs
, precision
);
1660 /* Find the high bit. */
1664 mask
= (cpp_num_part
) 1 << (i
- PART_PRECISION
);
1665 for (; ; i
--, mask
>>= 1)
1666 if (rhs
.high
& mask
)
1671 if (precision
> PART_PRECISION
)
1672 i
= precision
- PART_PRECISION
- 1;
1675 mask
= (cpp_num_part
) 1 << i
;
1676 for (; ; i
--, mask
>>= 1)
1682 if (!pfile
->state
.skip_eval
)
1683 cpp_error (pfile
, CPP_DL_ERROR
, "division by zero in #if");
1687 /* First nonzero bit of RHS is bit I. Do naive division by
1688 shifting the RHS fully left, and subtracting from LHS if LHS is
1689 at least as big, and then repeating but with one less shift.
1690 This is not very efficient, but is easy to understand. */
1692 rhs
.unsignedp
= true;
1693 lhs
.unsignedp
= true;
1694 i
= precision
- i
- 1;
1695 sub
= num_lshift (rhs
, precision
, i
);
1697 result
.high
= result
.low
= 0;
1700 if (num_greater_eq (lhs
, sub
, precision
))
1702 lhs
= num_binary_op (pfile
, lhs
, sub
, CPP_MINUS
);
1703 if (i
>= PART_PRECISION
)
1704 result
.high
|= (cpp_num_part
) 1 << (i
- PART_PRECISION
);
1706 result
.low
|= (cpp_num_part
) 1 << i
;
1710 sub
.low
= (sub
.low
>> 1) | (sub
.high
<< (PART_PRECISION
- 1));
1714 /* We divide so that the remainder has the sign of the LHS. */
1717 result
.unsignedp
= unsignedp
;
1718 result
.overflow
= false;
1722 result
= num_negate (result
, precision
);
1723 result
.overflow
= (num_positive (result
, precision
) ^ !negate
1724 && !num_zerop (result
));
1731 lhs
.unsignedp
= unsignedp
;
1732 lhs
.overflow
= false;
1734 lhs
= num_negate (lhs
, precision
);