Skip to content

Subtypes of graph_nodet can override DOT output #2913

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
merged 1 commit into from
Sep 11, 2018

Conversation

karkhaz
Copy link
Collaborator

@karkhaz karkhaz commented Sep 7, 2018

This commit introduces a virtual pretty() method to graph_nodet, whose
default implementation has the same behaviour as before (only outputting
the node's graph index with no attributes when dumped to a Graphviz DOT
file). Subtypes of graph_nodet can override this method to provide a
more informative representation of themselves when grapht::output_dot()
is called.

src/util/graph.h Outdated
///
/// If this function returns an empty string for a particular node,
/// grapht::output_dot() method will not output this node at all, nor any of
/// its incoming or outgoing edges.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use an optional type where the empty optional triggers this behavior. I'm not sure the actual behavior is exactly as describe, wouldn't we still output some edges which are coming into to these nodes?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I'm going to remove this from this PR and add a cleaner implementation in a different PR

src/util/graph.h Outdated
@@ -924,8 +960,14 @@ void grapht<N>::output_dot(std::ostream &out) const
for_each_successor(i, f);
};

const auto to_string = [](const node_indext &i) { return std::to_string(i); };
output_dot_generic<node_indext>(out, for_each_node, for_each_succ, to_string);
const auto to_string = [&](const node_indext &i) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need this &?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I replaced the & with this, we do need to capture this.

src/util/graph.h Outdated
const std::string pretty = node_to_pretty(i);
if(pretty == "")
return;
out << pretty << ";\n";
for_each_succ(i, [&](const node_index_type &n) {
out << node_to_string(i) << " -> " << node_to_string(n) << '\n';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will only produce a correct graph when pretty starts with the result of node_to_string. It would be better to enforce it in some way.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, you're right. I've just pushed a cleaner implementation that enforces this.

Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passed Diffblue compatibility checks (cbmc commit: e1dcf60).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/84093354

@karkhaz karkhaz force-pushed the kk-graph-pretty-nodes branch 2 times, most recently from 628986d to 324b68f Compare September 7, 2018 08:58
@karkhaz
Copy link
Collaborator Author

karkhaz commented Sep 7, 2018

Some motivation for this PR. Before:
before
After:
after

src/util/graph.h Outdated
}

public:
std::string pretty(node_indext idx) const
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

node_indext could be const reference

src/util/graph.h Outdated
@@ -16,9 +16,11 @@ Author: Daniel Kroening, [email protected]
#include <cassert>
#include <functional>
#include <iosfwd>
#include <iostream>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it needed?

This commit introduces a virtual pretty() method to graph_nodet, whose
default implementation has the same behaviour as before (only outputting
the node's graph index with no attributes when dumped to a Graphviz DOT
file). Subtypes of graph_nodet can override this method to provide a
more informative representation of themselves when grapht::output_dot()
is called.
@karkhaz karkhaz force-pushed the kk-graph-pretty-nodes branch from 324b68f to 37fc17f Compare September 7, 2018 09:34
Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR failed Diffblue compatibility checks (cbmc commit: 324b68f).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/84103467
Status will be re-evaluated on next push.
Please contact @peterschrammel, @thk123, or @allredj for support.

Common spurious failures:

  • the cbmc commit has disappeared in the mean time (e.g. in a force-push)
  • the author is not in the list of contributors (e.g. first-time contributors).

Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR failed Diffblue compatibility checks (cbmc commit: 628986d).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/84104004
Status will be re-evaluated on next push.
Please contact @peterschrammel, @thk123, or @allredj for support.

Common spurious failures:

  • the cbmc commit has disappeared in the mean time (e.g. in a force-push)
  • the author is not in the list of contributors (e.g. first-time contributors).

Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passed Diffblue compatibility checks (cbmc commit: 37fc17f).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/84107718

@karkhaz
Copy link
Collaborator Author

karkhaz commented Sep 7, 2018

Thank you @romainbrenguier, I applied your suggestions. All tests are passing.

@karkhaz
Copy link
Collaborator Author

karkhaz commented Sep 11, 2018

@peterschrammel not sure why you assigned me? I don't think I have access to merge this...

@peterschrammel peterschrammel merged commit d706891 into diffblue:develop Sep 11, 2018
@karkhaz karkhaz deleted the kk-graph-pretty-nodes branch September 11, 2018 12:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants