Mercurial > hg > CbC > CbC_gcc
comparison libcpp/expr.c @ 55:77e2b8dfacca gcc-4.4.5
update it from 4.4.3 to 4.5.0
author | ryoma <e075725@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 12 Feb 2010 23:39:51 +0900 |
parents | a06113de4d67 |
children | b7f97abdc517 |
comparison
equal
deleted
inserted
replaced
52:c156f1bd5cd9 | 55:77e2b8dfacca |
---|---|
50 static cpp_num num_inequality_op (cpp_reader *, cpp_num, cpp_num, | 50 static cpp_num num_inequality_op (cpp_reader *, cpp_num, cpp_num, |
51 enum cpp_ttype); | 51 enum cpp_ttype); |
52 static cpp_num num_equality_op (cpp_reader *, cpp_num, cpp_num, | 52 static cpp_num num_equality_op (cpp_reader *, cpp_num, cpp_num, |
53 enum cpp_ttype); | 53 enum cpp_ttype); |
54 static cpp_num num_mul (cpp_reader *, cpp_num, cpp_num); | 54 static cpp_num num_mul (cpp_reader *, cpp_num, cpp_num); |
55 static cpp_num num_div_op (cpp_reader *, cpp_num, cpp_num, enum cpp_ttype); | 55 static cpp_num num_div_op (cpp_reader *, cpp_num, cpp_num, enum cpp_ttype, |
56 source_location); | |
56 static cpp_num num_lshift (cpp_num, size_t, size_t); | 57 static cpp_num num_lshift (cpp_num, size_t, size_t); |
57 static cpp_num num_rshift (cpp_num, size_t, size_t); | 58 static cpp_num num_rshift (cpp_num, size_t, size_t); |
58 | 59 |
59 static cpp_num append_digit (cpp_num, int, int, size_t); | 60 static cpp_num append_digit (cpp_num, int, int, size_t); |
60 static cpp_num parse_defined (cpp_reader *); | 61 static cpp_num parse_defined (cpp_reader *); |
80 length LEN, possibly zero. Returns 0 for an invalid suffix, or a | 81 length LEN, possibly zero. Returns 0 for an invalid suffix, or a |
81 flag vector describing the suffix. */ | 82 flag vector describing the suffix. */ |
82 static unsigned int | 83 static unsigned int |
83 interpret_float_suffix (const uchar *s, size_t len) | 84 interpret_float_suffix (const uchar *s, size_t len) |
84 { | 85 { |
85 size_t f, l, w, q, i, d; | 86 size_t flags; |
86 size_t r, k, u, h; | 87 size_t f, d, l, w, q, i; |
87 | 88 |
88 f = l = w = q = i = d = 0; | 89 flags = 0; |
89 r = k = u = h = 0; | 90 f = d = l = w = q = i = 0; |
90 | 91 |
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')) | |
95 { | |
96 bool uppercase = (*s == 'D'); | |
97 switch (s[1]) | |
98 { | |
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; | |
105 default: | |
106 /* Additional two-character suffixes beginning with D are not | |
107 for decimal float constants. */ | |
108 break; | |
109 } | |
110 } | |
111 | |
112 /* Recognize a fixed-point suffix. */ | |
113 switch (s[len-1]) | |
114 { | |
115 case 'k': case 'K': flags = CPP_N_ACCUM; break; | |
116 case 'r': case 'R': flags = CPP_N_FRACT; break; | |
117 default: break; | |
118 } | |
119 | |
120 /* Continue processing a fixed-point suffix. The suffix is case | |
121 insensitive except for ll or LL. Order is significant. */ | |
122 if (flags) | |
123 { | |
124 if (len == 1) | |
125 return flags; | |
126 len--; | |
127 | |
128 if (*s == 'u' || *s == 'U') | |
129 { | |
130 flags |= CPP_N_UNSIGNED; | |
131 if (len == 1) | |
132 return flags; | |
133 len--; | |
134 s++; | |
135 } | |
136 | |
137 switch (*s) | |
138 { | |
139 case 'h': case 'H': | |
140 if (len == 1) | |
141 return flags |= CPP_N_SMALL; | |
142 break; | |
143 case 'l': | |
144 if (len == 1) | |
145 return flags |= CPP_N_MEDIUM; | |
146 if (len == 2 && s[1] == 'l') | |
147 return flags |= CPP_N_LARGE; | |
148 break; | |
149 case 'L': | |
150 if (len == 1) | |
151 return flags |= CPP_N_MEDIUM; | |
152 if (len == 2 && s[1] == 'L') | |
153 return flags |= CPP_N_LARGE; | |
154 break; | |
155 default: | |
156 break; | |
157 } | |
158 /* Anything left at this point is invalid. */ | |
159 return 0; | |
160 } | |
161 | |
162 /* In any remaining valid suffix, the case and order don't matter. */ | |
91 while (len--) | 163 while (len--) |
92 switch (s[len]) | 164 switch (s[len]) |
93 { | 165 { |
94 case 'r': case 'R': r++; break; | 166 case 'f': case 'F': f++; break; |
95 case 'k': case 'K': k++; break; | 167 case 'd': case 'D': d++; break; |
96 case 'u': case 'U': u++; break; | 168 case 'l': case 'L': l++; break; |
97 case 'h': case 'H': h++; break; | 169 case 'w': case 'W': w++; break; |
98 case 'f': case 'F': | 170 case 'q': case 'Q': q++; break; |
99 if (d > 0) | |
100 return 0; | |
101 f++; | |
102 break; | |
103 case 'l': case 'L': | |
104 if (d > 0) | |
105 return 0; | |
106 l++; | |
107 /* If there are two Ls, they must be adjacent and the same case. */ | |
108 if (l == 2 && s[len] != s[len + 1]) | |
109 return 0; | |
110 break; | |
111 case 'w': case 'W': | |
112 if (d > 0) | |
113 return 0; | |
114 w++; | |
115 break; | |
116 case 'q': case 'Q': | |
117 if (d > 0) | |
118 return 0; | |
119 q++; | |
120 break; | |
121 case 'i': case 'I': | 171 case 'i': case 'I': |
122 case 'j': case 'J': i++; break; | 172 case 'j': case 'J': i++; break; |
123 case 'd': case 'D': d++; break; | |
124 default: | 173 default: |
125 return 0; | 174 return 0; |
126 } | 175 } |
127 | 176 |
128 if (r + k > 1 || h > 1 || l > 2 || u > 1) | 177 if (f + d + l + w + q > 1 || i > 1) |
129 return 0; | |
130 | |
131 if (r == 1) | |
132 { | |
133 if (f || i || d || w || q) | |
134 return 0; | |
135 | |
136 return (CPP_N_FRACT | |
137 | (u ? CPP_N_UNSIGNED : 0) | |
138 | (h ? CPP_N_SMALL : | |
139 l == 2 ? CPP_N_LARGE : | |
140 l == 1 ? CPP_N_MEDIUM : 0)); | |
141 } | |
142 | |
143 if (k == 1) | |
144 { | |
145 if (f || i || d || w || q) | |
146 return 0; | |
147 | |
148 return (CPP_N_ACCUM | |
149 | (u ? CPP_N_UNSIGNED : 0) | |
150 | (h ? CPP_N_SMALL : | |
151 l == 2 ? CPP_N_LARGE : | |
152 l == 1 ? CPP_N_MEDIUM : 0)); | |
153 } | |
154 | |
155 if (f + l + w + q > 1 || i > 1 || h + u > 0) | |
156 return 0; | |
157 | |
158 /* Allow dd, df, dl suffixes for decimal float constants. */ | |
159 if (d && ((d + f + l != 2) || i)) | |
160 return 0; | 178 return 0; |
161 | 179 |
162 return ((i ? CPP_N_IMAGINARY : 0) | 180 return ((i ? CPP_N_IMAGINARY : 0) |
163 | (f ? CPP_N_SMALL : | 181 | (f ? CPP_N_SMALL : |
182 d ? CPP_N_MEDIUM : | |
164 l ? CPP_N_LARGE : | 183 l ? CPP_N_LARGE : |
165 w ? CPP_N_MD_W : | 184 w ? CPP_N_MD_W : |
166 q ? CPP_N_MD_Q : CPP_N_MEDIUM) | 185 q ? CPP_N_MD_Q : CPP_N_DEFAULT)); |
167 | (d ? CPP_N_DFLOAT : 0)); | |
168 } | 186 } |
169 | 187 |
170 /* Subroutine of cpp_classify_number. S points to an integer suffix | 188 /* Subroutine of cpp_classify_number. S points to an integer suffix |
171 of length LEN, possibly zero. Returns 0 for an invalid suffix, or a | 189 of length LEN, possibly zero. Returns 0 for an invalid suffix, or a |
172 flag vector describing the suffix. */ | 190 flag vector describing the suffix. */ |
349 && ! cpp_sys_macro_p (pfile)) | 367 && ! cpp_sys_macro_p (pfile)) |
350 cpp_error (pfile, CPP_DL_WARNING, | 368 cpp_error (pfile, CPP_DL_WARNING, |
351 "traditional C rejects the \"%.*s\" suffix", | 369 "traditional C rejects the \"%.*s\" suffix", |
352 (int) (limit - str), str); | 370 (int) (limit - str), str); |
353 | 371 |
372 /* A suffix for double is a GCC extension via decimal float support. | |
373 If the suffix also specifies an imaginary value we'll catch that | |
374 later. */ | |
375 if ((result == CPP_N_MEDIUM) && CPP_PEDANTIC (pfile)) | |
376 cpp_error (pfile, CPP_DL_PEDWARN, | |
377 "suffix for double constant is a GCC extension"); | |
378 | |
354 /* Radix must be 10 for decimal floats. */ | 379 /* Radix must be 10 for decimal floats. */ |
355 if ((result & CPP_N_DFLOAT) && radix != 10) | 380 if ((result & CPP_N_DFLOAT) && radix != 10) |
356 { | 381 { |
357 cpp_error (pfile, CPP_DL_ERROR, | 382 cpp_error (pfile, CPP_DL_ERROR, |
358 "invalid suffix \"%.*s\" with hexadecimal floating constant", | 383 "invalid suffix \"%.*s\" with hexadecimal floating constant", |
393 "traditional C rejects the \"%.*s\" suffix", | 418 "traditional C rejects the \"%.*s\" suffix", |
394 (int) (limit - str), str); | 419 (int) (limit - str), str); |
395 } | 420 } |
396 | 421 |
397 if ((result & CPP_N_WIDTH) == CPP_N_LARGE | 422 if ((result & CPP_N_WIDTH) == CPP_N_LARGE |
398 && ! CPP_OPTION (pfile, c99) | |
399 && CPP_OPTION (pfile, warn_long_long)) | 423 && CPP_OPTION (pfile, warn_long_long)) |
400 cpp_error (pfile, CPP_DL_PEDWARN, | 424 cpp_error (pfile, |
401 "use of C99 long long integer constant"); | 425 CPP_OPTION (pfile, c99) ? CPP_DL_WARNING : CPP_DL_PEDWARN, |
426 CPP_OPTION (pfile, cplusplus) | |
427 ? "use of C++0x long long integer constant" | |
428 : "use of C99 long long integer constant"); | |
402 | 429 |
403 result |= CPP_N_INTEGER; | 430 result |= CPP_N_INTEGER; |
404 } | 431 } |
405 | 432 |
406 syntax_ok: | 433 syntax_ok: |
510 else if (!result.unsignedp | 537 else if (!result.unsignedp |
511 && !(CPP_OPTION (pfile, traditional) | 538 && !(CPP_OPTION (pfile, traditional) |
512 && pfile->state.in_directive) | 539 && pfile->state.in_directive) |
513 && !num_positive (result, precision)) | 540 && !num_positive (result, precision)) |
514 { | 541 { |
542 /* This is for constants within the range of uintmax_t but | |
543 not that of intmax_t. For such decimal constants, a | |
544 diagnostic is required for C99 as the selected type must | |
545 be signed and not having a type is a constraint violation | |
546 (DR#298, TC3), so this must be a pedwarn. For C90, | |
547 unsigned long is specified to be used for a constant that | |
548 does not fit in signed long; if uintmax_t has the same | |
549 range as unsigned long this means only a warning is | |
550 appropriate here. C90 permits the preprocessor to use a | |
551 wider range than unsigned long in the compiler, so if | |
552 uintmax_t is wider than unsigned long no diagnostic is | |
553 required for such constants in preprocessor #if | |
554 expressions and the compiler will pedwarn for such | |
555 constants outside the range of unsigned long that reach | |
556 the compiler so a diagnostic is not required there | |
557 either; thus, pedwarn for C99 but use a plain warning for | |
558 C90. */ | |
515 if (base == 10) | 559 if (base == 10) |
516 cpp_error (pfile, CPP_DL_WARNING, | 560 cpp_error (pfile, (CPP_OPTION (pfile, c99) |
561 ? CPP_DL_PEDWARN | |
562 : CPP_DL_WARNING), | |
517 "integer constant is so large that it is unsigned"); | 563 "integer constant is so large that it is unsigned"); |
518 result.unsignedp = true; | 564 result.unsignedp = true; |
519 } | 565 } |
520 } | 566 } |
521 | 567 |
604 token = cpp_get_token (pfile); | 650 token = cpp_get_token (pfile); |
605 } | 651 } |
606 | 652 |
607 if (token->type == CPP_NAME) | 653 if (token->type == CPP_NAME) |
608 { | 654 { |
609 node = token->val.node; | 655 node = token->val.node.node; |
610 if (paren && cpp_get_token (pfile)->type != CPP_CLOSE_PAREN) | 656 if (paren && cpp_get_token (pfile)->type != CPP_CLOSE_PAREN) |
611 { | 657 { |
612 cpp_error (pfile, CPP_DL_ERROR, "missing ')' after \"defined\""); | 658 cpp_error (pfile, CPP_DL_ERROR, "missing ')' after \"defined\""); |
613 node = 0; | 659 node = 0; |
614 } | 660 } |
724 } | 770 } |
725 } | 771 } |
726 break; | 772 break; |
727 | 773 |
728 case CPP_NAME: | 774 case CPP_NAME: |
729 if (token->val.node == pfile->spec_nodes.n_defined) | 775 if (token->val.node.node == pfile->spec_nodes.n_defined) |
730 return parse_defined (pfile); | 776 return parse_defined (pfile); |
731 else if (CPP_OPTION (pfile, cplusplus) | 777 else if (CPP_OPTION (pfile, cplusplus) |
732 && (token->val.node == pfile->spec_nodes.n_true | 778 && (token->val.node.node == pfile->spec_nodes.n_true |
733 || token->val.node == pfile->spec_nodes.n_false)) | 779 || token->val.node.node == pfile->spec_nodes.n_false)) |
734 { | 780 { |
735 result.high = 0; | 781 result.high = 0; |
736 result.low = (token->val.node == pfile->spec_nodes.n_true); | 782 result.low = (token->val.node.node == pfile->spec_nodes.n_true); |
737 } | 783 } |
738 else | 784 else |
739 { | 785 { |
740 result.high = 0; | 786 result.high = 0; |
741 result.low = 0; | 787 result.low = 0; |
742 if (CPP_OPTION (pfile, warn_undef) && !pfile->state.skip_eval) | 788 if (CPP_OPTION (pfile, warn_undef) && !pfile->state.skip_eval) |
743 cpp_error (pfile, CPP_DL_WARNING, "\"%s\" is not defined", | 789 cpp_error (pfile, CPP_DL_WARNING, "\"%s\" is not defined", |
744 NODE_NAME (token->val.node)); | 790 NODE_NAME (token->val.node.node)); |
745 } | 791 } |
746 break; | 792 break; |
747 | 793 |
748 case CPP_HASH: | 794 case CPP_HASH: |
749 if (!pfile->state.skipping) | 795 if (!pfile->state.skipping) |
1076 break; | 1122 break; |
1077 | 1123 |
1078 case CPP_DIV: | 1124 case CPP_DIV: |
1079 case CPP_MOD: | 1125 case CPP_MOD: |
1080 top[-1].value = num_div_op (pfile, top[-1].value, | 1126 top[-1].value = num_div_op (pfile, top[-1].value, |
1081 top->value, top->op); | 1127 top->value, top->op, top->loc); |
1082 top[-1].loc = top->loc; | 1128 top[-1].loc = top->loc; |
1083 break; | 1129 break; |
1084 | 1130 |
1085 case CPP_OR_OR: | 1131 case CPP_OR_OR: |
1086 top--; | 1132 top--; |
1621 result.unsignedp = unsignedp; | 1667 result.unsignedp = unsignedp; |
1622 | 1668 |
1623 return result; | 1669 return result; |
1624 } | 1670 } |
1625 | 1671 |
1626 /* Divide two preprocessing numbers, returning the answer or the | 1672 /* Divide two preprocessing numbers, LHS and RHS, returning the answer |
1627 remainder depending upon OP. */ | 1673 or the remainder depending upon OP. LOCATION is the source location |
1674 of this operator (for diagnostics). */ | |
1675 | |
1628 static cpp_num | 1676 static cpp_num |
1629 num_div_op (cpp_reader *pfile, cpp_num lhs, cpp_num rhs, enum cpp_ttype op) | 1677 num_div_op (cpp_reader *pfile, cpp_num lhs, cpp_num rhs, enum cpp_ttype op, |
1678 source_location location) | |
1630 { | 1679 { |
1631 cpp_num result, sub; | 1680 cpp_num result, sub; |
1632 cpp_num_part mask; | 1681 cpp_num_part mask; |
1633 bool unsignedp = lhs.unsignedp || rhs.unsignedp; | 1682 bool unsignedp = lhs.unsignedp || rhs.unsignedp; |
1634 bool negate = false, lhs_neg = false; | 1683 bool negate = false, lhs_neg = false; |
1664 break; | 1713 break; |
1665 } | 1714 } |
1666 else | 1715 else |
1667 { | 1716 { |
1668 if (!pfile->state.skip_eval) | 1717 if (!pfile->state.skip_eval) |
1669 cpp_error (pfile, CPP_DL_ERROR, "division by zero in #if"); | 1718 cpp_error_with_line (pfile, CPP_DL_ERROR, location, 0, |
1719 "division by zero in #if"); | |
1670 return lhs; | 1720 return lhs; |
1671 } | 1721 } |
1672 | 1722 |
1673 /* First nonzero bit of RHS is bit I. Do naive division by | 1723 /* First nonzero bit of RHS is bit I. Do naive division by |
1674 shifting the RHS fully left, and subtracting from LHS if LHS is | 1724 shifting the RHS fully left, and subtracting from LHS if LHS is |