-
Notifications
You must be signed in to change notification settings - Fork 276
introduce goto_programt::instructiont::type() and _nonconst() #6412
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
Conversation
6e560e2
to
a116534
Compare
Codecov Report
@@ Coverage Diff @@
## develop #6412 +/- ##
========================================
Coverage 75.98% 75.98%
========================================
Files 1524 1524
Lines 164242 164241 -1
========================================
Hits 124801 124801
+ Misses 39441 39440 -1
Continue to review full report at Codecov.
|
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 think by introducing turn_into_assume
(we've already got turn_into_skip
), we can do without type_nonconst()
.
i1->source_location_nonconst() = instruction.source_location(); | ||
i1->code_nonconst() = code_declt(symbol_expr); | ||
|
||
i2->type=ASSIGN; | ||
i2->type_nonconst() = ASSIGN; |
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.
use the 2-param variant of insert_after
?
@@ -120,11 +120,11 @@ void uninitializedt::add_assertions( | |||
id2string(identifier)+"#initialized"; | |||
|
|||
symbol_exprt symbol_expr(new_identifier, bool_typet()); | |||
i1->type=DECL; | |||
i1->type_nonconst() = DECL; |
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.
use the 2-param variant of insert_after
?
@@ -421,7 +421,7 @@ bool remove_exceptionst::instrument_throw( | |||
exc_thrown, | |||
typecast_exprt(exc_expr, exc_thrown.type())); | |||
// now turn the `throw' into `assignment' | |||
instr_it->type=ASSIGN; | |||
instr_it->type_nonconst() = ASSIGN; |
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.
swap?
@@ -846,7 +846,7 @@ void disjunctive_polynomial_accelerationt::build_fixed() | |||
{ | |||
if(instruction.is_assert()) | |||
{ | |||
instruction.type = ASSUME; | |||
instruction.type_nonconst() = ASSUME; |
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.
turn_into_assume?
This method turns a GOTO or an ASSERT instruction into an ASSUME with the same condition. This is a common pattern in the code base, and introducing the method enables doing so in a way that is guaranteed to preserve the class invariants.
a116534
to
3e5b976
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.
Seems reasonable.
/// Set the kind of the instruction. | ||
/// This method is best avoided to prevent mal-formed instructions. | ||
/// Consider using the goto_programt::make_X methods instead. | ||
goto_program_instruction_typet &type_nonconst() |
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.
As this only has 7 users, would it be better to just refactor those and not have this functionality at all? Alternatively, could this be marked as deprecated?
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.
Aren't we even down to 2 users, one of which can easily be fixed and the other being read_bin_goto_object
? I think the latter could be handled by some low-level constructor that likely wants to be private
with access only permitted via a friend
declaration.
I've added |
3e5b976
to
a6255d4
Compare
This introduces two methods to read and write the type of a GOTO program instruction, and replaces various direct accesses.
a6255d4
to
13c2919
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.
It would be great to figure out a story for the nonconst
case right away.
const auto back_edge = add_instruction(back_edge_location, instructions); | ||
back_edge->type = GOTO; | ||
back_edge->type_nonconst() = GOTO; |
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't we use make_goto
for this one?
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.
add_instruction() in that unit test should be replaced altogether, but this goes beyond this PR.
/// Set the kind of the instruction. | ||
/// This method is best avoided to prevent mal-formed instructions. | ||
/// Consider using the goto_programt::make_X methods instead. | ||
goto_program_instruction_typet &type_nonconst() |
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.
Aren't we even down to 2 users, one of which can easily be fixed and the other being read_bin_goto_object
? I think the latter could be handled by some low-level constructor that likely wants to be private
with access only permitted via a friend
declaration.
Changing |
This introduces two methods to read and write the type of a GOTO program
instruction, and replaces various direct accesses.