Reduce the number of integer types that need to be handled.

This commit is contained in:
Victor Zverovich 2014-06-21 09:40:04 -07:00
parent 5e6f57ada1
commit 5be9a8de3f
2 changed files with 23 additions and 34 deletions

View File

@ -507,10 +507,6 @@ fmt::ULongLong fmt::BasicWriter<Char>::GetIntValue(const ArgInfo &arg) {
return arg.int_value;
case UINT:
return arg.uint_value;
case LONG:
return arg.long_value;
case ULONG:
return arg.ulong_value;
case LONG_LONG:
return arg.long_long_value;
case ULONG_LONG:
@ -556,7 +552,7 @@ void fmt::BasicWriter<Char>::FormatParser::CheckSign(
report_error_(s,
fmt::Format("format specifier '{}' requires numeric argument") << sign);
}
if (arg.type == UINT || arg.type == ULONG || arg.type == ULONG_LONG) {
if (arg.type == UINT || arg.type == ULONG_LONG) {
report_error_(s,
fmt::Format("format specifier '{}' requires signed argument") << sign);
}
@ -767,12 +763,6 @@ void fmt::BasicWriter<Char>::PrintfParser::Format(
case UINT:
writer.FormatInt(arg.uint_value, spec);
break;
case LONG:
writer.FormatInt(arg.long_value, spec);
break;
case ULONG:
writer.FormatInt(arg.ulong_value, spec);
break;
case LONG_LONG:
writer.FormatInt(arg.long_long_value, spec);
break;
@ -963,14 +953,6 @@ void fmt::BasicWriter<Char>::FormatParser::Format(
case UINT:
value = precision_arg.uint_value;
break;
case LONG:
if (precision_arg.long_value < 0)
report_error_(s, "negative precision in format");
value = precision_arg.long_value;
break;
case ULONG:
value = precision_arg.ulong_value;
break;
case LONG_LONG:
if (precision_arg.long_long_value < 0)
report_error_(s, "negative precision in format");
@ -1014,12 +996,6 @@ void fmt::BasicWriter<Char>::FormatParser::Format(
case UINT:
writer.FormatInt(arg.uint_value, spec);
break;
case LONG:
writer.FormatInt(arg.long_value, spec);
break;
case ULONG:
writer.FormatInt(arg.ulong_value, spec);
break;
case LONG_LONG:
writer.FormatInt(arg.long_long_value, spec);
break;

View File

@ -891,11 +891,10 @@ class BasicWriter {
void operator<<(typename internal::CharTraits<Char>::UnsupportedStrType);
enum Type {
// Numeric types should go first.
INT, UINT, LONG, ULONG, LONG_LONG, ULONG_LONG,
LAST_INTEGER_TYPE = ULONG_LONG,
DOUBLE, LONG_DOUBLE,
LAST_NUMERIC_TYPE = LONG_DOUBLE,
// Integer types should go first,
INT, UINT, LONG_LONG, ULONG_LONG, LAST_INTEGER_TYPE = ULONG_LONG,
// followed by floating-point types.
DOUBLE, LONG_DOUBLE, LAST_NUMERIC_TYPE = LONG_DOUBLE,
CHAR, STRING, WSTRING, POINTER, CUSTOM
};
@ -920,8 +919,6 @@ class BasicWriter {
int int_value;
unsigned uint_value;
double double_value;
long long_value;
unsigned long ulong_value;
LongLong long_long_value;
ULongLong ulong_long_value;
long double long_double_value;
@ -962,8 +959,24 @@ class BasicWriter {
BasicArg(unsigned short value) { type = UINT; this->int_value = value; }
BasicArg(int value) { type = INT; this->int_value = value; }
BasicArg(unsigned value) { type = UINT; this->uint_value = value; }
BasicArg(long value) { type = LONG; this->long_value = value; }
BasicArg(unsigned long value) { type = ULONG; this->ulong_value = value; }
BasicArg(long value) {
if (sizeof(long) == sizeof(int)) {
type = INT;
this->int_value = static_cast<int>(value);
} else {
type = LONG_LONG;
this->long_long_value = value;
}
}
BasicArg(unsigned long value) {
if (sizeof(unsigned long) == sizeof(unsigned)) {
type = UINT;
this->uint_value = static_cast<unsigned>(value);
} else {
type = ULONG_LONG;
this->ulong_long_value = value;
}
}
BasicArg(LongLong value) {
type = LONG_LONG;
this->long_long_value = value;