Skip to content

Commit 4da669d

Browse files
Add property output functions
Plain text, XML and JSON output for property results.
1 parent cc1a90e commit 4da669d

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/goto-checker/properties.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Author: Daniel Kroening, Peter Schrammel
1212
#include "properties.h"
1313

1414
#include <util/invariant.h>
15+
#include <util/json.h>
16+
#include <util/xml.h>
1517

1618
std::string as_string(resultt result)
1719
{
@@ -89,6 +91,31 @@ propertiest initialize_properties(const abstract_goto_modelt &goto_model)
8991
return properties;
9092
}
9193

94+
std::string
95+
as_string(const irep_idt &property_id, const property_infot &property_info)
96+
{
97+
return "[" + id2string(property_id) + "] " + property_info.description +
98+
": " + as_string(property_info.status);
99+
}
100+
101+
xmlt xml(const irep_idt &property_id, const property_infot &property_info)
102+
{
103+
xmlt xml_result("result");
104+
xml_result.set_attribute("property", id2string(property_id));
105+
xml_result.set_attribute("status", as_string(property_info.status));
106+
return xml_result;
107+
}
108+
109+
json_objectt
110+
json(const irep_idt &property_id, const property_infot &property_info)
111+
{
112+
json_objectt result;
113+
result["property"] = json_stringt(property_id);
114+
result["description"] = json_stringt(property_info.description);
115+
result["status"] = json_stringt(as_string(property_info.status));
116+
return result;
117+
}
118+
92119
std::size_t
93120
count_properties(const propertiest &properties, property_statust status)
94121
{

src/goto-checker/properties.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ Author: Daniel Kroening, Peter Schrammel
1616

1717
#include <goto-programs/goto_model.h>
1818

19+
class json_objectt;
20+
class xmlt;
21+
1922
/// The status of a property
2023
enum class property_statust
2124
{
@@ -73,6 +76,14 @@ typedef std::unordered_map<irep_idt, property_infot> propertiest;
7376
/// Returns the properties in the goto model
7477
propertiest initialize_properties(const abstract_goto_modelt &);
7578

79+
std::string
80+
as_string(const irep_idt &property_id, const property_infot &property_info);
81+
82+
xmlt xml(const irep_idt &property_id, const property_infot &property_info);
83+
84+
json_objectt
85+
json(const irep_idt &property_id, const property_infot &property_info);
86+
7687
/// Return the number of properties with given \p status
7788
std::size_t count_properties(const propertiest &, property_statust);
7889

0 commit comments

Comments
 (0)