🔨 further cleanup

This commit is contained in:
Niels Lohmann 2017-02-12 18:50:17 +01:00
parent c2d55109c1
commit c8191c8172
No known key found for this signature in database
GPG Key ID: 7F3CEA63AE251B69
5 changed files with 61 additions and 57 deletions

View File

@ -94,7 +94,7 @@ cppcheck:
# run clang sanitize (we are overrding the CXXFLAGS provided by travis in order to use gcc's libstdc++) # run clang sanitize (we are overrding the CXXFLAGS provided by travis in order to use gcc's libstdc++)
clang_sanitize: clean clang_sanitize: clean
CXX=clang++ CXXFLAGS="-g -O2 -fsanitize=address -fsanitize=undefined -fno-omit-frame-pointer" $(MAKE) CXX=clang++ CXXFLAGS="-g -O2 -fsanitize=address -fsanitize=undefined -fno-omit-frame-pointer" $(MAKE) check
########################################################################## ##########################################################################

View File

@ -9444,8 +9444,8 @@ class basic_json
literal_false, ///< the `false` literal literal_false, ///< the `false` literal
literal_null, ///< the `null` literal literal_null, ///< the `null` literal
value_string, ///< a string -- use get_string() for actual value value_string, ///< a string -- use get_string() for actual value
value_unsigned_integer, ///< an unsigned integer -- use get_number() for actual value value_unsigned, ///< an unsigned integer -- use get_number() for actual value
value_signed_integer, ///< a signed integer -- use get_number() for actual value value_integer, ///< a signed integer -- use get_number() for actual value
value_float, ///< an floating point number -- use get_number() for actual value value_float, ///< an floating point number -- use get_number() for actual value
begin_array, ///< the character for array begin `[` begin_array, ///< the character for array begin `[`
begin_object, ///< the character for object begin `{` begin_object, ///< the character for object begin `{`
@ -9598,8 +9598,8 @@ class basic_json
return "null literal"; return "null literal";
case token_type::value_string: case token_type::value_string:
return "string literal"; return "string literal";
case lexer::token_type::value_unsigned_integer: case lexer::token_type::value_unsigned:
case lexer::token_type::value_signed_integer: case lexer::token_type::value_integer:
case lexer::token_type::value_float: case lexer::token_type::value_float:
return "number literal"; return "number literal";
case token_type::begin_array: case token_type::begin_array:
@ -9903,7 +9903,7 @@ basic_json_parser_13:
} }
basic_json_parser_14: basic_json_parser_14:
{ {
last_token_type = token_type::value_unsigned_integer; last_token_type = token_type::value_unsigned;
break; break;
} }
basic_json_parser_15: basic_json_parser_15:
@ -10301,7 +10301,7 @@ basic_json_parser_43:
} }
basic_json_parser_44: basic_json_parser_44:
{ {
last_token_type = token_type::value_signed_integer; last_token_type = token_type::value_integer;
break; break;
} }
basic_json_parser_45: basic_json_parser_45:
@ -11091,19 +11091,19 @@ basic_json_parser_71:
{ {
assert(m_start != nullptr); assert(m_start != nullptr);
assert(m_start < m_cursor); assert(m_start < m_cursor);
assert((token == token_type::value_unsigned_integer) or assert((token == token_type::value_unsigned) or
(token == token_type::value_signed_integer) or (token == token_type::value_integer) or
(token == token_type::value_float)); (token == token_type::value_float));
strtonum num(reinterpret_cast<const char*>(m_start), strtonum num_converter(reinterpret_cast<const char*>(m_start),
reinterpret_cast<const char*>(m_cursor)); reinterpret_cast<const char*>(m_cursor));
switch (token) switch (token)
{ {
case lexer::token_type::value_unsigned_integer: case lexer::token_type::value_unsigned:
{ {
number_unsigned_t val{0}; number_unsigned_t val;
if (num.to(val)) if (num_converter.to(val))
{ {
result.m_type = value_t::number_unsigned; result.m_type = value_t::number_unsigned;
result.m_value = val; result.m_value = val;
@ -11112,10 +11112,10 @@ basic_json_parser_71:
break; break;
} }
case lexer::token_type::value_signed_integer: case lexer::token_type::value_integer:
{ {
number_integer_t val{0}; number_integer_t val;
if (num.to(val)) if (num_converter.to(val))
{ {
result.m_type = value_t::number_integer; result.m_type = value_t::number_integer;
result.m_value = val; result.m_value = val;
@ -11130,8 +11130,10 @@ basic_json_parser_71:
} }
} }
number_float_t val{0}; // parse float (either explicitly or because a previous conversion
if (not num.to(val)) // failed)
number_float_t val;
if (not num_converter.to(val))
{ {
// couldn't parse as float_t // couldn't parse as float_t
result.m_type = value_t::discarded; result.m_type = value_t::discarded;
@ -11390,8 +11392,8 @@ basic_json_parser_71:
break; break;
} }
case lexer::token_type::value_unsigned_integer: case lexer::token_type::value_unsigned:
case lexer::token_type::value_signed_integer: case lexer::token_type::value_integer:
case lexer::token_type::value_float: case lexer::token_type::value_float:
{ {
m_lexer.get_number(result, last_token); m_lexer.get_number(result, last_token);

View File

@ -9444,8 +9444,8 @@ class basic_json
literal_false, ///< the `false` literal literal_false, ///< the `false` literal
literal_null, ///< the `null` literal literal_null, ///< the `null` literal
value_string, ///< a string -- use get_string() for actual value value_string, ///< a string -- use get_string() for actual value
value_unsigned_integer, ///< an unsigned integer -- use get_number() for actual value value_unsigned, ///< an unsigned integer -- use get_number() for actual value
value_signed_integer, ///< a signed integer -- use get_number() for actual value value_integer, ///< a signed integer -- use get_number() for actual value
value_float, ///< an floating point number -- use get_number() for actual value value_float, ///< an floating point number -- use get_number() for actual value
begin_array, ///< the character for array begin `[` begin_array, ///< the character for array begin `[`
begin_object, ///< the character for object begin `{` begin_object, ///< the character for object begin `{`
@ -9598,8 +9598,8 @@ class basic_json
return "null literal"; return "null literal";
case token_type::value_string: case token_type::value_string:
return "string literal"; return "string literal";
case lexer::token_type::value_unsigned_integer: case lexer::token_type::value_unsigned:
case lexer::token_type::value_signed_integer: case lexer::token_type::value_integer:
case lexer::token_type::value_float: case lexer::token_type::value_float:
return "number literal"; return "number literal";
case token_type::begin_array: case token_type::begin_array:
@ -9699,9 +9699,9 @@ class basic_json
frac = decimal_point digit+; frac = decimal_point digit+;
int = (zero | digit_1_9 digit*); int = (zero | digit_1_9 digit*);
number_unsigned = int; number_unsigned = int;
number_unsigned { last_token_type = token_type::value_unsigned_integer; break; } number_unsigned { last_token_type = token_type::value_unsigned; break; }
number_signed = minus int; number_integer = minus int;
number_signed { last_token_type = token_type::value_signed_integer; break; } number_integer { last_token_type = token_type::value_integer; break; }
number_float = minus? int frac? exp?; number_float = minus? int frac? exp?;
number_float { last_token_type = token_type::value_float; break; } number_float { last_token_type = token_type::value_float; break; }
@ -10163,19 +10163,19 @@ class basic_json
{ {
assert(m_start != nullptr); assert(m_start != nullptr);
assert(m_start < m_cursor); assert(m_start < m_cursor);
assert((token == token_type::value_unsigned_integer) or assert((token == token_type::value_unsigned) or
(token == token_type::value_signed_integer) or (token == token_type::value_integer) or
(token == token_type::value_float)); (token == token_type::value_float));
strtonum num(reinterpret_cast<const char*>(m_start), strtonum num_converter(reinterpret_cast<const char*>(m_start),
reinterpret_cast<const char*>(m_cursor)); reinterpret_cast<const char*>(m_cursor));
switch (token) switch (token)
{ {
case lexer::token_type::value_unsigned_integer: case lexer::token_type::value_unsigned:
{ {
number_unsigned_t val{0}; number_unsigned_t val;
if (num.to(val)) if (num_converter.to(val))
{ {
result.m_type = value_t::number_unsigned; result.m_type = value_t::number_unsigned;
result.m_value = val; result.m_value = val;
@ -10184,10 +10184,10 @@ class basic_json
break; break;
} }
case lexer::token_type::value_signed_integer: case lexer::token_type::value_integer:
{ {
number_integer_t val{0}; number_integer_t val;
if (num.to(val)) if (num_converter.to(val))
{ {
result.m_type = value_t::number_integer; result.m_type = value_t::number_integer;
result.m_value = val; result.m_value = val;
@ -10202,8 +10202,10 @@ class basic_json
} }
} }
number_float_t val{0}; // parse float (either explicitly or because a previous conversion
if (not num.to(val)) // failed)
number_float_t val;
if (not num_converter.to(val))
{ {
// couldn't parse as float_t // couldn't parse as float_t
result.m_type = value_t::discarded; result.m_type = value_t::discarded;
@ -10462,8 +10464,8 @@ class basic_json
break; break;
} }
case lexer::token_type::value_unsigned_integer: case lexer::token_type::value_unsigned:
case lexer::token_type::value_signed_integer: case lexer::token_type::value_integer:
case lexer::token_type::value_float: case lexer::token_type::value_float:
{ {
m_lexer.get_number(result, last_token); m_lexer.get_number(result, last_token);

View File

@ -65,30 +65,30 @@ TEST_CASE("lexer class")
SECTION("numbers") SECTION("numbers")
{ {
CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("0"), CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("0"),
1).scan() == json::lexer::token_type::value_unsigned_integer)); 1).scan() == json::lexer::token_type::value_unsigned));
CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("1"), CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("1"),
1).scan() == json::lexer::token_type::value_unsigned_integer)); 1).scan() == json::lexer::token_type::value_unsigned));
CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("2"), CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("2"),
1).scan() == json::lexer::token_type::value_unsigned_integer)); 1).scan() == json::lexer::token_type::value_unsigned));
CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("3"), CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("3"),
1).scan() == json::lexer::token_type::value_unsigned_integer)); 1).scan() == json::lexer::token_type::value_unsigned));
CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("4"), CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("4"),
1).scan() == json::lexer::token_type::value_unsigned_integer)); 1).scan() == json::lexer::token_type::value_unsigned));
CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("5"), CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("5"),
1).scan() == json::lexer::token_type::value_unsigned_integer)); 1).scan() == json::lexer::token_type::value_unsigned));
CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("6"), CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("6"),
1).scan() == json::lexer::token_type::value_unsigned_integer)); 1).scan() == json::lexer::token_type::value_unsigned));
CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("7"), CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("7"),
1).scan() == json::lexer::token_type::value_unsigned_integer)); 1).scan() == json::lexer::token_type::value_unsigned));
CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("8"), CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("8"),
1).scan() == json::lexer::token_type::value_unsigned_integer)); 1).scan() == json::lexer::token_type::value_unsigned));
CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("9"), CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("9"),
1).scan() == json::lexer::token_type::value_unsigned_integer)); 1).scan() == json::lexer::token_type::value_unsigned));
CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("-0"), CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("-0"),
2).scan() == json::lexer::token_type::value_signed_integer)); 2).scan() == json::lexer::token_type::value_integer));
CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("-1"), CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("-1"),
2).scan() == json::lexer::token_type::value_signed_integer)); 2).scan() == json::lexer::token_type::value_integer));
CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("1.1"), CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("1.1"),
3).scan() == json::lexer::token_type::value_float)); 3).scan() == json::lexer::token_type::value_float));
@ -121,8 +121,8 @@ TEST_CASE("lexer class")
CHECK((json::lexer::token_type_name(json::lexer::token_type::literal_false) == "false literal")); CHECK((json::lexer::token_type_name(json::lexer::token_type::literal_false) == "false literal"));
CHECK((json::lexer::token_type_name(json::lexer::token_type::literal_null) == "null literal")); CHECK((json::lexer::token_type_name(json::lexer::token_type::literal_null) == "null literal"));
CHECK((json::lexer::token_type_name(json::lexer::token_type::value_string) == "string literal")); CHECK((json::lexer::token_type_name(json::lexer::token_type::value_string) == "string literal"));
CHECK((json::lexer::token_type_name(json::lexer::token_type::value_unsigned_integer) == "number literal")); CHECK((json::lexer::token_type_name(json::lexer::token_type::value_unsigned) == "number literal"));
CHECK((json::lexer::token_type_name(json::lexer::token_type::value_signed_integer) == "number literal")); CHECK((json::lexer::token_type_name(json::lexer::token_type::value_integer) == "number literal"));
CHECK((json::lexer::token_type_name(json::lexer::token_type::value_float) == "number literal")); CHECK((json::lexer::token_type_name(json::lexer::token_type::value_float) == "number literal"));
CHECK((json::lexer::token_type_name(json::lexer::token_type::begin_array) == "'['")); CHECK((json::lexer::token_type_name(json::lexer::token_type::begin_array) == "'['"));
CHECK((json::lexer::token_type_name(json::lexer::token_type::begin_object) == "'{'")); CHECK((json::lexer::token_type_name(json::lexer::token_type::begin_object) == "'{'"));

View File

@ -417,7 +417,7 @@ TEST_CASE("regression tests")
// disabled, because locale-specific beharivor is not // disabled, because locale-specific beharivor is not
// triggered in AppVeyor for some reason // triggered in AppVeyor for some reason
#if 0 #ifndef _MSC_VER
{ {
// verify that strtod now uses commas as decimal-separator // verify that strtod now uses commas as decimal-separator
CHECK(std::strtod("3,14", nullptr) == 3.14); CHECK(std::strtod("3,14", nullptr) == 3.14);