+static void parse_integer_suffix(bool is_oct_hex)
+{
+ bool is_unsigned = false;
+ bool min_long = false;
+ bool min_longlong = false;
+ bool not_traditional = false;
+ int pos = 0;
+ char suffix[4];
+
+ if (c == 'U' || c == 'u') {
+ not_traditional = true;
+ suffix[pos++] = toupper(c);
+ is_unsigned = true;
+ next_char();
+ if (c == 'L' || c == 'l') {
+ suffix[pos++] = toupper(c);
+ min_long = true;
+ next_char();
+ if (c == 'L' || c == 'l') {
+ suffix[pos++] = toupper(c);
+ min_longlong = true;
+ next_char();
+ }
+ }
+ } else if (c == 'l' || c == 'L') {
+ suffix[pos++] = toupper(c);
+ min_long = true;
+ next_char();
+ if (c == 'l' || c == 'L') {
+ not_traditional = true;
+ suffix[pos++] = toupper(c);
+ min_longlong = true;
+ next_char();
+ if (c == 'u' || c == 'U') {
+ suffix[pos++] = toupper(c);
+ is_unsigned = true;
+ next_char();
+ }
+ } else if (c == 'u' || c == 'U') {
+ not_traditional = true;
+ suffix[pos++] = toupper(c);
+ is_unsigned = true;
+ next_char();
+ lexer_token.datatype = type_unsigned_long;
+ }
+ }
+
+ if (warning.traditional && not_traditional) {
+ suffix[pos] = '\0';
+ warningf(&lexer_token.source_position,
+ "traditional C rejects the '%s' suffix", suffix);
+ }
+ if (!is_unsigned) {
+ long long v = lexer_token.v.intvalue;
+ if (!min_long) {
+ if (v >= TARGET_INT_MIN && v <= TARGET_INT_MAX) {
+ lexer_token.datatype = type_int;
+ return;
+ } else if (is_oct_hex && v >= 0 && v <= TARGET_UINT_MAX) {
+ lexer_token.datatype = type_unsigned_int;
+ return;
+ }
+ }
+ if (!min_longlong) {
+ if (v >= TARGET_LONG_MIN && v <= TARGET_LONG_MAX) {
+ lexer_token.datatype = type_long;
+ return;
+ } else if (is_oct_hex && v >= 0 && (unsigned long long)v <= (unsigned long long)TARGET_ULONG_MAX) {
+ lexer_token.datatype = type_unsigned_long;
+ return;
+ }
+ }
+ unsigned long long uv = (unsigned long long) v;
+ if (is_oct_hex && uv > (unsigned long long) TARGET_LONGLONG_MAX) {
+ lexer_token.datatype = type_unsigned_long_long;
+ return;
+ }
+
+ lexer_token.datatype = type_long_long;
+ } else {
+ unsigned long long v = (unsigned long long) lexer_token.v.intvalue;
+ if (!min_long && v <= TARGET_UINT_MAX) {
+ lexer_token.datatype = type_unsigned_int;
+ return;
+ }
+ if (!min_longlong && v <= TARGET_ULONG_MAX) {
+ lexer_token.datatype = type_unsigned_long;
+ return;
+ }
+ lexer_token.datatype = type_unsigned_long_long;
+ }
+}
+
+static void parse_floating_suffix(void)
+{
+ switch(c) {
+ /* TODO: do something useful with the suffixes... */
+ case 'f':
+ case 'F':
+ if (warning.traditional) {
+ warningf(&lexer_token.source_position,
+ "traditional C rejects the 'F' suffix");
+ }
+ next_char();
+ lexer_token.datatype = type_float;
+ break;
+ case 'l':
+ case 'L':
+ if (warning.traditional) {
+ warningf(&lexer_token.source_position,
+ "traditional C rejects the 'F' suffix");
+ }
+ next_char();
+ lexer_token.datatype = type_long_double;
+ break;
+ default:
+ lexer_token.datatype = type_double;
+ break;
+ }
+}
+
+/**
+ * A replacement for strtoull. Only those parts needed for
+ * our parser are implemented.
+ */
+static unsigned long long parse_int_string(const char *s, const char **endptr, int base) {
+ unsigned long long v = 0;
+
+ switch (base) {
+ case 16:
+ for (;; ++s) {
+ /* check for overrun */
+ if (v >= 0x1000000000000000ULL)
+ break;
+ switch (tolower(*s)) {
+ case '0': v <<= 4; break;
+ case '1': v <<= 4; v |= 0x1; break;
+ case '2': v <<= 4; v |= 0x2; break;
+ case '3': v <<= 4; v |= 0x3; break;
+ case '4': v <<= 4; v |= 0x4; break;
+ case '5': v <<= 4; v |= 0x5; break;
+ case '6': v <<= 4; v |= 0x6; break;
+ case '7': v <<= 4; v |= 0x7; break;
+ case '8': v <<= 4; v |= 0x8; break;
+ case '9': v <<= 4; v |= 0x9; break;
+ case 'a': v <<= 4; v |= 0xa; break;
+ case 'b': v <<= 4; v |= 0xb; break;
+ case 'c': v <<= 4; v |= 0xc; break;
+ case 'd': v <<= 4; v |= 0xd; break;
+ case 'e': v <<= 4; v |= 0xe; break;
+ case 'f': v <<= 4; v |= 0xf; break;
+ default:
+ goto end;
+ }
+ }
+ break;
+ case 8:
+ for (;; ++s) {
+ /* check for overrun */
+ if (v >= 0x2000000000000000ULL)
+ break;
+ switch (tolower(*s)) {
+ case '0': v <<= 3; break;
+ case '1': v <<= 3; v |= 1; break;
+ case '2': v <<= 3; v |= 2; break;
+ case '3': v <<= 3; v |= 3; break;
+ case '4': v <<= 3; v |= 4; break;
+ case '5': v <<= 3; v |= 5; break;
+ case '6': v <<= 3; v |= 6; break;
+ case '7': v <<= 3; v |= 7; break;
+ default:
+ goto end;
+ }
+ }
+ break;
+ case 10:
+ for (;; ++s) {
+ /* check for overrun */
+ if (v > 0x1999999999999999ULL)
+ break;
+ switch (tolower(*s)) {
+ case '0': v *= 10; break;
+ case '1': v *= 10; v += 1; break;
+ case '2': v *= 10; v += 2; break;
+ case '3': v *= 10; v += 3; break;
+ case '4': v *= 10; v += 4; break;
+ case '5': v *= 10; v += 5; break;
+ case '6': v *= 10; v += 6; break;
+ case '7': v *= 10; v += 7; break;
+ case '8': v *= 10; v += 8; break;
+ case '9': v *= 10; v += 9; break;
+ default:
+ goto end;
+ }
+ }
+ break;
+ default:
+ assert(0);
+ break;
+ }
+end:
+ *endptr = s;
+ return v;
+}
+
+/**
+ * Parses a hex number including hex floats and set the
+ * lexer_token.
+ */