static unsigned int
interpret_float_suffix (const uchar *s, size_t len)
{
- size_t f = 0, l = 0, i = 0, d = 0;
+ size_t f, l, w, q, i, d;
+
+ f = l = w = q = i = d = 0;
while (len--)
switch (s[len])
{
- case 'f': case 'F': f++; break;
- case 'l': case 'L': l++; break;
- case 'i': case 'I':
- case 'j': case 'J': i++; break;
- case 'd': case 'D':
- /* Disallow fd, ld suffixes. */
- if (d && (f || l))
+ case 'f': case 'F':
+ if (d > 0)
+ return 0;
+ f++;
+ break;
+ case 'l': case 'L':
+ if (d > 0)
return 0;
- d++;
+ l++;
break;
+ case 'w': case 'W':
+ if (d > 0)
+ return 0;
+ w++;
+ break;
+ case 'q': case 'Q':
+ if (d > 0)
+ return 0;
+ q++;
+ break;
+ case 'i': case 'I':
+ case 'j': case 'J': i++; break;
+ case 'd': case 'D': d++; break;
default:
return 0;
}
- if (f + l > 1 || i > 1)
+ if (f + l + w + q > 1 || i > 1)
return 0;
/* Allow dd, df, dl suffixes for decimal float constants. */
return ((i ? CPP_N_IMAGINARY : 0)
| (f ? CPP_N_SMALL :
- l ? CPP_N_LARGE : CPP_N_MEDIUM)
+ l ? CPP_N_LARGE :
+ w ? CPP_N_MD_W :
+ q ? CPP_N_MD_Q : CPP_N_MEDIUM)
| (d ? CPP_N_DFLOAT : 0));
}
radix = 16;
str++;
}
+ else if ((*str == 'b' || *str == 'B') && (str[1] == '0' || str[1] == '1'))
+ {
+ radix = 2;
+ str++;
+ }
}
/* Now scan for a well-formed integer or float. */
radix = 10;
if (max_digit >= radix)
- SYNTAX_ERROR2 ("invalid digit \"%c\" in octal constant", '0' + max_digit);
+ {
+ if (radix == 2)
+ SYNTAX_ERROR2 ("invalid digit \"%c\" in binary constant", '0' + max_digit);
+ else
+ SYNTAX_ERROR2 ("invalid digit \"%c\" in octal constant", '0' + max_digit);
+ }
if (float_flag != NOT_FLOAT)
{
+ if (radix == 2)
+ {
+ cpp_error (pfile, CPP_DL_ERROR,
+ "invalid prefix \"0b\" for floating constant");
+ return CPP_N_INVALID;
+ }
+
if (radix == 16 && CPP_PEDANTIC (pfile) && !CPP_OPTION (pfile, c99))
cpp_error (pfile, CPP_DL_PEDWARN,
"use of C99 hexadecimal floating constant");
return CPP_N_INVALID;
}
+ if ((result & CPP_N_DFLOAT) && CPP_PEDANTIC (pfile))
+ cpp_error (pfile, CPP_DL_PEDWARN,
+ "decimal float constants are a GCC extension");
+
result |= CPP_N_FLOATING;
}
else
if ((result & CPP_N_IMAGINARY) && CPP_PEDANTIC (pfile))
cpp_error (pfile, CPP_DL_PEDWARN,
"imaginary constants are a GCC extension");
+ if (radix == 2 && CPP_PEDANTIC (pfile))
+ cpp_error (pfile, CPP_DL_PEDWARN,
+ "binary constants are a GCC extension");
if (radix == 10)
result |= CPP_N_DECIMAL;
else if (radix == 16)
result |= CPP_N_HEX;
+ else if (radix == 2)
+ result |= CPP_N_BINARY;
else
result |= CPP_N_OCTAL;
base = 16;
p += 2;
}
+ else if ((type & CPP_N_RADIX) == CPP_N_BINARY)
+ {
+ base = 2;
+ p += 2;
+ }
/* We can add a digit to numbers strictly less than this without
needing the precision and slowness of double integers. */
append_digit (cpp_num num, int digit, int base, size_t precision)
{
cpp_num result;
- unsigned int shift = 3 + (base == 16);
+ unsigned int shift;
bool overflow;
cpp_num_part add_high, add_low;
- /* Multiply by 8 or 16. Catching this overflow here means we don't
+ /* Multiply by 2, 8 or 16. Catching this overflow here means we don't
need to worry about add_high overflowing. */
+ switch (base)
+ {
+ case 2:
+ shift = 1;
+ break;
+
+ case 16:
+ shift = 4;
+ break;
+
+ default:
+ shift = 3;
+ }
overflow = !!(num.high >> (PART_PRECISION - shift));
result.high = num.high << shift;
result.low = num.low << shift;
if (add_low + digit < add_low)
add_high++;
add_low += digit;
-
+
if (result.low + add_low < result.low)
add_high++;
if (result.high + add_high < result.high)
/* RSHIFT */ {13, LEFT_ASSOC},
/* LSHIFT */ {13, LEFT_ASSOC},
- /* MIN */ {10, LEFT_ASSOC | CHECK_PROMOTION},
- /* MAX */ {10, LEFT_ASSOC | CHECK_PROMOTION},
-
/* COMPL */ {16, NO_L_OPERAND},
/* AND_AND */ {6, LEFT_ASSOC},
/* OR_OR */ {5, LEFT_ASSOC},
case CPP_MINUS:
case CPP_RSHIFT:
case CPP_LSHIFT:
- case CPP_MIN:
- case CPP_MAX:
case CPP_COMMA:
top[-1].value = num_binary_op (pfile, top[-1].value,
top->value, top->op);
{
cpp_num result;
size_t precision = CPP_OPTION (pfile, precision);
- bool gte;
size_t n;
switch (op)
lhs = num_rshift (lhs, precision, n);
break;
- /* Min / Max. */
- case CPP_MIN:
- case CPP_MAX:
- {
- bool unsignedp = lhs.unsignedp || rhs.unsignedp;
-
- gte = num_greater_eq (lhs, rhs, precision);
- if (op == CPP_MIN)
- gte = !gte;
- if (!gte)
- lhs = rhs;
- lhs.unsignedp = unsignedp;
- }
- break;
-
/* Arithmetic. */
case CPP_MINUS:
rhs = num_negate (rhs, precision);
{
if (negate)
result = num_negate (result, precision);
- result.overflow = num_positive (result, precision) ^ !negate;
+ result.overflow = (num_positive (result, precision) ^ !negate
+ && !num_zerop (result));
}
return result;