Commit 07622278 by Martin Liska Committed by Martin Liska

Come up with json::integer_number and use it in GCOV.

2019-10-22  Martin Liska  <mliska@suse.cz>

	* diagnostic-format-json.cc (json_from_expanded_location):
	Use json::integer_number.
	* gcov.c (output_intermediate_json_line): Use new
	json::integer_number.
	(output_json_intermediate_file): Likewise.
	* json.cc (number::print): Move to ...
	(float_number::print): ... this.
	(integer_number::print): New.
	(test_writing_numbers): Move to ...
	(test_writing_float_numbers): ... this.
	(test_writing_integer_numbers): New.
	(json_cc_tests): Register test_writing_integer_numbers.
	* json.h (class value): Add forward declaration
	for float_number and integer_number.
	(enum kind): Add JSON_INTEGER and JSON_FLOAT.
	(class number): Move to ...
	(class float_number): ... this.
	(class integer_number): New.
	* optinfo-emit-json.cc (optrecord_json_writer::impl_location_to_json):
	Use json::integer_number.
	(optrecord_json_writer::location_to_json): Likewise.
	(optrecord_json_writer::profile_count_to_json): Likewise.
	(optrecord_json_writer::pass_to_json): Likewise.

From-SVN: r277284
parent fc25649c
2019-10-22 Martin Liska <mliska@suse.cz>
* diagnostic-format-json.cc (json_from_expanded_location):
Use json::integer_number.
* gcov.c (output_intermediate_json_line): Use new
json::integer_number.
(output_json_intermediate_file): Likewise.
* json.cc (number::print): Move to ...
(float_number::print): ... this.
(integer_number::print): New.
(test_writing_numbers): Move to ...
(test_writing_float_numbers): ... this.
(test_writing_integer_numbers): New.
(json_cc_tests): Register test_writing_integer_numbers.
* json.h (class value): Add forward declaration
for float_number and integer_number.
(enum kind): Add JSON_INTEGER and JSON_FLOAT.
(class number): Move to ...
(class float_number): ... this.
(class integer_number): New.
* optinfo-emit-json.cc (optrecord_json_writer::impl_location_to_json):
Use json::integer_number.
(optrecord_json_writer::location_to_json): Likewise.
(optrecord_json_writer::profile_count_to_json): Likewise.
(optrecord_json_writer::pass_to_json): Likewise.
2019-10-22 Richard Sandiford <richard.sandiford@arm.com> 2019-10-22 Richard Sandiford <richard.sandiford@arm.com>
* tree-vect-slp.c (vect_slp_bb_region): Check whether * tree-vect-slp.c (vect_slp_bb_region): Check whether
...@@ -48,8 +48,8 @@ json_from_expanded_location (location_t loc) ...@@ -48,8 +48,8 @@ json_from_expanded_location (location_t loc)
json::object *result = new json::object (); json::object *result = new json::object ();
if (exploc.file) if (exploc.file)
result->set ("file", new json::string (exploc.file)); result->set ("file", new json::string (exploc.file));
result->set ("line", new json::number (exploc.line)); result->set ("line", new json::integer_number (exploc.line));
result->set ("column", new json::number (exploc.column)); result->set ("column", new json::integer_number (exploc.column));
return result; return result;
} }
......
...@@ -1061,10 +1061,10 @@ output_intermediate_json_line (json::array *object, ...@@ -1061,10 +1061,10 @@ output_intermediate_json_line (json::array *object,
return; return;
json::object *lineo = new json::object (); json::object *lineo = new json::object ();
lineo->set ("line_number", new json::number (line_num)); lineo->set ("line_number", new json::integer_number (line_num));
if (function_name != NULL) if (function_name != NULL)
lineo->set ("function_name", new json::string (function_name)); lineo->set ("function_name", new json::string (function_name));
lineo->set ("count", new json::number (line->count)); lineo->set ("count", new json::integer_number (line->count));
lineo->set ("unexecuted_block", lineo->set ("unexecuted_block",
new json::literal (line->has_unexecuted_block)); new json::literal (line->has_unexecuted_block));
...@@ -1079,7 +1079,7 @@ output_intermediate_json_line (json::array *object, ...@@ -1079,7 +1079,7 @@ output_intermediate_json_line (json::array *object,
if (!(*it)->is_unconditional && !(*it)->is_call_non_return) if (!(*it)->is_unconditional && !(*it)->is_call_non_return)
{ {
json::object *branch = new json::object (); json::object *branch = new json::object ();
branch->set ("count", new json::number ((*it)->count)); branch->set ("count", new json::integer_number ((*it)->count));
branch->set ("throw", new json::literal ((*it)->is_throw)); branch->set ("throw", new json::literal ((*it)->is_throw));
branch->set ("fallthrough", branch->set ("fallthrough",
new json::literal ((*it)->fall_through)); new json::literal ((*it)->fall_through));
...@@ -1138,16 +1138,19 @@ output_json_intermediate_file (json::array *json_files, source_info *src) ...@@ -1138,16 +1138,19 @@ output_json_intermediate_file (json::array *json_files, source_info *src)
function->set ("name", new json::string ((*it)->m_name)); function->set ("name", new json::string ((*it)->m_name));
function->set ("demangled_name", function->set ("demangled_name",
new json::string ((*it)->get_demangled_name ())); new json::string ((*it)->get_demangled_name ()));
function->set ("start_line", new json::number ((*it)->start_line)); function->set ("start_line",
function->set ("start_column", new json::number ((*it)->start_column)); new json::integer_number ((*it)->start_line));
function->set ("end_line", new json::number ((*it)->end_line)); function->set ("start_column",
function->set ("end_column", new json::number ((*it)->end_column)); new json::integer_number ((*it)->start_column));
function->set ("end_line", new json::integer_number ((*it)->end_line));
function->set ("end_column",
new json::integer_number ((*it)->end_column));
function->set ("blocks", function->set ("blocks",
new json::number ((*it)->get_block_count ())); new json::integer_number ((*it)->get_block_count ()));
function->set ("blocks_executed", function->set ("blocks_executed",
new json::number ((*it)->blocks_executed)); new json::integer_number ((*it)->blocks_executed));
function->set ("execution_count", function->set ("execution_count",
new json::number ((*it)->blocks[0].count)); new json::integer_number ((*it)->blocks[0].count));
functions->append (function); functions->append (function);
} }
......
...@@ -154,18 +154,31 @@ array::append (value *v) ...@@ -154,18 +154,31 @@ array::append (value *v)
m_elements.safe_push (v); m_elements.safe_push (v);
} }
/* class json::number, a subclass of json::value, wrapping a double. */ /* class json::float_number, a subclass of json::value, wrapping a double. */
/* Implementation of json::value::print for json::number. */ /* Implementation of json::value::print for json::float_number. */
void void
number::print (pretty_printer *pp) const float_number::print (pretty_printer *pp) const
{ {
char tmp[1024]; char tmp[1024];
snprintf (tmp, sizeof (tmp), "%g", m_value); snprintf (tmp, sizeof (tmp), "%g", m_value);
pp_string (pp, tmp); pp_string (pp, tmp);
} }
/* class json::integer_number, a subclass of json::value, wrapping a long. */
/* Implementation of json::value::print for json::integer_number. */
void
integer_number::print (pretty_printer *pp) const
{
char tmp[1024];
snprintf (tmp, sizeof (tmp), "%ld", m_value);
pp_string (pp, tmp);
}
/* class json::string, a subclass of json::value. */ /* class json::string, a subclass of json::value. */
/* json::string's ctor. */ /* json::string's ctor. */
...@@ -297,11 +310,22 @@ test_writing_arrays () ...@@ -297,11 +310,22 @@ test_writing_arrays ()
/* Verify that JSON numbers are written correctly. */ /* Verify that JSON numbers are written correctly. */
static void static void
test_writing_numbers () test_writing_float_numbers ()
{
assert_print_eq (float_number (0), "0");
assert_print_eq (float_number (42), "42");
assert_print_eq (float_number (-100), "-100");
assert_print_eq (float_number (123456789), "1.23457e+08");
}
static void
test_writing_integer_numbers ()
{ {
assert_print_eq (number (0), "0"); assert_print_eq (integer_number (0), "0");
assert_print_eq (number (42), "42"); assert_print_eq (integer_number (42), "42");
assert_print_eq (number (-100), "-100"); assert_print_eq (integer_number (-100), "-100");
assert_print_eq (integer_number (123456789), "123456789");
assert_print_eq (integer_number (-123456789), "-123456789");
} }
/* Verify that JSON strings are written correctly. */ /* Verify that JSON strings are written correctly. */
...@@ -337,7 +361,8 @@ json_cc_tests () ...@@ -337,7 +361,8 @@ json_cc_tests ()
test_object_get (); test_object_get ();
test_writing_objects (); test_writing_objects ();
test_writing_arrays (); test_writing_arrays ();
test_writing_numbers (); test_writing_float_numbers ();
test_writing_integer_numbers ();
test_writing_strings (); test_writing_strings ();
test_writing_literals (); test_writing_literals ();
} }
......
...@@ -39,7 +39,8 @@ namespace json ...@@ -39,7 +39,8 @@ namespace json
class value; class value;
class object; class object;
class array; class array;
class number; class float_number;
class integer_number;
class string; class string;
class literal; class literal;
...@@ -53,8 +54,11 @@ enum kind ...@@ -53,8 +54,11 @@ enum kind
/* class json::array. */ /* class json::array. */
JSON_ARRAY, JSON_ARRAY,
/* class json::number. */ /* class json::integer_number. */
JSON_NUMBER, JSON_INTEGER,
/* class json::float_number. */
JSON_FLOAT,
/* class json::string. */ /* class json::string. */
JSON_STRING, JSON_STRING,
...@@ -114,14 +118,14 @@ class array : public value ...@@ -114,14 +118,14 @@ class array : public value
auto_vec<value *> m_elements; auto_vec<value *> m_elements;
}; };
/* Subclass of value for numbers. */ /* Subclass of value for floating-point numbers. */
class number : public value class float_number : public value
{ {
public: public:
number (double value) : m_value (value) {} float_number (double value) : m_value (value) {}
enum kind get_kind () const FINAL OVERRIDE { return JSON_NUMBER; } enum kind get_kind () const FINAL OVERRIDE { return JSON_FLOAT; }
void print (pretty_printer *pp) const FINAL OVERRIDE; void print (pretty_printer *pp) const FINAL OVERRIDE;
double get () const { return m_value; } double get () const { return m_value; }
...@@ -130,6 +134,23 @@ class number : public value ...@@ -130,6 +134,23 @@ class number : public value
double m_value; double m_value;
}; };
/* Subclass of value for integer-valued numbers. */
class integer_number : public value
{
public:
integer_number (long value) : m_value (value) {}
enum kind get_kind () const FINAL OVERRIDE { return JSON_INTEGER; }
void print (pretty_printer *pp) const FINAL OVERRIDE;
long get () const { return m_value; }
private:
long m_value;
};
/* Subclass of value for strings. */ /* Subclass of value for strings. */
class string : public value class string : public value
......
...@@ -181,7 +181,7 @@ optrecord_json_writer::impl_location_to_json (dump_impl_location_t loc) ...@@ -181,7 +181,7 @@ optrecord_json_writer::impl_location_to_json (dump_impl_location_t loc)
{ {
json::object *obj = new json::object (); json::object *obj = new json::object ();
obj->set ("file", new json::string (loc.m_file)); obj->set ("file", new json::string (loc.m_file));
obj->set ("line", new json::number (loc.m_line)); obj->set ("line", new json::integer_number (loc.m_line));
if (loc.m_function) if (loc.m_function)
obj->set ("function", new json::string (loc.m_function)); obj->set ("function", new json::string (loc.m_function));
return obj; return obj;
...@@ -196,8 +196,8 @@ optrecord_json_writer::location_to_json (location_t loc) ...@@ -196,8 +196,8 @@ optrecord_json_writer::location_to_json (location_t loc)
expanded_location exploc = expand_location (loc); expanded_location exploc = expand_location (loc);
json::object *obj = new json::object (); json::object *obj = new json::object ();
obj->set ("file", new json::string (exploc.file)); obj->set ("file", new json::string (exploc.file));
obj->set ("line", new json::number (exploc.line)); obj->set ("line", new json::integer_number (exploc.line));
obj->set ("column", new json::number (exploc.column)); obj->set ("column", new json::integer_number (exploc.column));
return obj; return obj;
} }
...@@ -207,7 +207,7 @@ json::object * ...@@ -207,7 +207,7 @@ json::object *
optrecord_json_writer::profile_count_to_json (profile_count count) optrecord_json_writer::profile_count_to_json (profile_count count)
{ {
json::object *obj = new json::object (); json::object *obj = new json::object ();
obj->set ("value", new json::number (count.to_gcov_type ())); obj->set ("value", new json::integer_number (count.to_gcov_type ()));
obj->set ("quality", obj->set ("quality",
new json::string (profile_quality_as_string (count.quality ()))); new json::string (profile_quality_as_string (count.quality ())));
return obj; return obj;
...@@ -262,7 +262,7 @@ optrecord_json_writer::pass_to_json (opt_pass *pass) ...@@ -262,7 +262,7 @@ optrecord_json_writer::pass_to_json (opt_pass *pass)
&& (pass->optinfo_flags & optgroup->value)) && (pass->optinfo_flags & optgroup->value))
optgroups->append (new json::string (optgroup->name)); optgroups->append (new json::string (optgroup->name));
} }
obj->set ("num", new json::number (pass->static_pass_number)); obj->set ("num", new json::integer_number (pass->static_pass_number));
return obj; return obj;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment