-
Notifications
You must be signed in to change notification settings - Fork 275
Add improved functionality for the construction of json_arrayt and json_objectt #3862
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
thomasspriggs
merged 7 commits into
diffblue:develop
from
thomasspriggs:tas/json_construction
Jan 28, 2019
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a8de5e5
Add initializer_list constructor to `json_objectt`
thomasspriggs 5be69b7
Add initializer_list constructor to `json_arrayt`
thomasspriggs 773603c
Add support for range to construct json_arrayt and json_objectt
thomasspriggs 74bbcf0
Refactor `static_verifier_json` using `range`
thomasspriggs 0226ae1
Add cast operator from `ranget` to a container
thomasspriggs d2c756a
Remove unnecessary brackets in constructon of `json_objectt`
thomasspriggs 2a4d8ff
Remove unused constructors from backing container
thomasspriggs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ Author: Martin Brain, [email protected] | |
#include <util/message.h> | ||
#include <util/namespace.h> | ||
#include <util/options.h> | ||
#include <util/range.h> | ||
|
||
#include <goto-programs/goto_model.h> | ||
|
||
|
@@ -20,48 +21,42 @@ Author: Martin Brain, [email protected] | |
struct static_verifier_resultt | ||
{ | ||
// clang-format off | ||
enum { TRUE, FALSE, BOTTOM, UNKNOWN } status; | ||
enum statust { TRUE, FALSE, BOTTOM, UNKNOWN } status; | ||
// clang-format on | ||
source_locationt source_location; | ||
irep_idt function_id; | ||
}; | ||
|
||
/// Makes a status message string from a status. | ||
static const char *message(const static_verifier_resultt::statust &status) | ||
{ | ||
switch(status) | ||
{ | ||
case static_verifier_resultt::TRUE: | ||
return "SUCCESS"; | ||
case static_verifier_resultt::FALSE: | ||
return "FAILURE (if reachable)"; | ||
case static_verifier_resultt::BOTTOM: | ||
return "SUCCESS (unreachable)"; | ||
case static_verifier_resultt::UNKNOWN: | ||
return "UNKNOWN"; | ||
} | ||
UNREACHABLE; | ||
} | ||
|
||
static void static_verifier_json( | ||
const std::vector<static_verifier_resultt> &results, | ||
messaget &m, | ||
std::ostream &out) | ||
{ | ||
m.status() << "Writing JSON report" << messaget::eom; | ||
|
||
json_arrayt json_result; | ||
|
||
for(const auto &result : results) | ||
{ | ||
json_objectt &j = json_result.push_back().make_object(); | ||
|
||
switch(result.status) | ||
{ | ||
case static_verifier_resultt::TRUE: | ||
j["status"] = json_stringt("SUCCESS"); | ||
break; | ||
|
||
case static_verifier_resultt::FALSE: | ||
j["status"] = json_stringt("FAILURE (if reachable)"); | ||
break; | ||
|
||
case static_verifier_resultt::BOTTOM: | ||
j["status"] = json_stringt("SUCCESS (unreachable)"); | ||
break; | ||
|
||
case static_verifier_resultt::UNKNOWN: | ||
j["status"] = json_stringt("UNKNOWN"); | ||
break; | ||
} | ||
|
||
j["sourceLocation"] = json(result.source_location); | ||
} | ||
|
||
out << json_result; | ||
out << make_range(results) | ||
.map([](const static_verifier_resultt &result) { | ||
return json_objectt{ | ||
{"status", json_stringt{message(result.status)}}, | ||
{"sourceLocation", json(result.source_location)}}; | ||
}) | ||
.collect<json_arrayt>(); | ||
} | ||
|
||
static void static_verifier_xml( | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -172,8 +172,8 @@ json_objectt json(const typet &type, const namespacet &ns, const irep_idt &mode) | |
to_struct_type(type).components(); | ||
for(const auto &component : components) | ||
{ | ||
json_objectt e({{"name", json_stringt(component.get_name())}, | ||
{"type", json(component.type(), ns, mode)}}); | ||
json_objectt e{{"name", json_stringt(component.get_name())}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same formatting nitpick as above |
||
{"type", json(component.type(), ns, mode)}}; | ||
members.push_back(std::move(e)); | ||
} | ||
} | ||
|
@@ -185,8 +185,8 @@ json_objectt json(const typet &type, const namespacet &ns, const irep_idt &mode) | |
to_union_type(type).components(); | ||
for(const auto &component : components) | ||
{ | ||
json_objectt e({{"name", json_stringt(component.get_name())}, | ||
{"type", json(component.type(), ns, mode)}}); | ||
json_objectt e{{"name", json_stringt(component.get_name())}, | ||
{"type", json(component.type(), ns, mode)}}; | ||
members.push_back(std::move(e)); | ||
} | ||
} | ||
|
@@ -348,8 +348,8 @@ json_objectt json(const exprt &expr, const namespacet &ns, const irep_idt &mode) | |
|
||
forall_operands(it, expr) | ||
{ | ||
json_objectt e({{"index", json_numbert(std::to_string(index))}, | ||
{"value", json(*it, ns, mode)}}); | ||
json_objectt e{{"index", json_numbert(std::to_string(index))}, | ||
{"value", json(*it, ns, mode)}}; | ||
elements.push_back(std::move(e)); | ||
index++; | ||
} | ||
|
@@ -370,8 +370,8 @@ json_objectt json(const exprt &expr, const namespacet &ns, const irep_idt &mode) | |
json_arrayt &members = result["members"].make_array(); | ||
for(std::size_t m = 0; m < expr.operands().size(); m++) | ||
{ | ||
json_objectt e({{"value", json(expr.operands()[m], ns, mode)}, | ||
{"name", json_stringt(components[m].get_name())}}); | ||
json_objectt e{{"value", json(expr.operands()[m], ns, mode)}, | ||
{"name", json_stringt(components[m].get_name())}}; | ||
members.push_back(std::move(e)); | ||
} | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Surprising formatting -- break after first
{
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I insert a new line, then clang format will just remove it again. I agree that left alignment of the enclosed pairs would be preferable. However I prefer the sub optimal formatting over the extra comments to switch off the formatting in this case.