-
Notifications
You must be signed in to change notification settings - Fork 275
Add validation of smt parse trees to construct smt_responset instances. #6458
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
Add validation of smt parse trees to construct smt_responset instances. #6458
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #6458 +/- ##
===========================================
+ Coverage 75.98% 75.99% +0.01%
===========================================
Files 1542 1546 +4
Lines 165038 165240 +202
===========================================
+ Hits 125404 125579 +175
- Misses 39634 39661 +27
Continue to review full report at Codecov.
|
2b91bf9
to
0e66013
Compare
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.
LGTM overall 👍🏻
@@ -37,5 +37,14 @@ template class response_or_errort<smt_responset>; | |||
|
|||
response_or_errort<smt_responset> validate_smt_response(const irept &parse_tree) | |||
{ | |||
if(parse_tree.id() == "sat") |
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.
⛏️ Why not switch (parse_tree.id()) { case "sat": }
. Might make it a bit more readable?
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.
Because you can't switch on a string in C++.
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.
😱
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.
But you can switch on a/the first character... so if you want a big nested tree of case statements... ;)
return {response_or_errort<smt_responset>{ | ||
"Error response has multiple error messages."}}; |
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.
Can we do something nicer here? Maybe gather all the error messages into a multiline string?
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.
I have done something nicer here. The original parse tree is now included in this error message, as instances where the messages are sub trees could also fall into this case.
@@ -37,5 +37,14 @@ template class response_or_errort<smt_responset>; | |||
|
|||
response_or_errort<smt_responset> validate_smt_response(const irept &parse_tree) | |||
{ | |||
if(parse_tree.id() == "sat") |
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.
But you can switch on a/the first character... so if you want a big nested tree of case statements... ;)
The `response_or_errort` class is a template, so that it can be reused for smt_termt and `smt_sortt` sub trees of the SMT responses, whilst maintaining strong compile time type checking. The `UNIMPLEMENTED` macro in the `validate_smt_response` function will be replaced with an implementation in the following commits of this PR.
To facilitate debugging of tests and tracking down causes of test failures.
So they can be reused in multiple test `.cpp` files.
For each non-leaf node in the `smt_responset` tree, the same logic is required where the child nodes are validated and we construct the non-leaf node if there are no errors, or collect and propagate the errors upwards if there are errors validating the child nodes. The template in this commit abstracts this logic out, so that it doesn't need to be duplicated for each type of node we construct.
This is currently implemented using `pretty`, but this function is used forward to replace with an implementation specific to our use case which is more easily readable by users of CBMC.
The template parameter is specified for mapping to upper case characters to fix a warning compiling on Ubuntu 18. This warning was related to `std::toupper` being declared with the deprecated `throw ()` in the standard library and the meaning of this changing between C++ versions.
So that it is still possible to see the error message which was being reported.
0e66013
to
6c3d1da
Compare
This PR adds validation of smt parse trees to construct smt_responset instances.