-
Notifications
You must be signed in to change notification settings - Fork 273
Use constructors with fewer parameters if possible, for dereference_exprt and plus_exprt #4524
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
Use constructors with fewer parameters if possible, for dereference_exprt and plus_exprt #4524
Conversation
f6f8e2f
to
ba7c8ac
Compare
I came across a few places where the single-parameter constructor was not used yet and the information about the type of the expression was duplicated, so I tidied up all occurrences of this that I could find.
The type of the plus_exprt is the type of the lhs by default. This is always the case in the code base.
ba7c8ac
to
cdb0133
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.
✔️
Passed Diffblue compatibility checks (cbmc commit: cdb0133).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/108163822
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.
My apologies for all the additional wishlist-type requests. This is very nice cleanup, it just invites even more cleanup...
dereference_exprt old_array(this_symbol.symbol_expr(), struct_tag_type); | ||
dereference_exprt new_array(local_symexpr, struct_tag_type); | ||
dereference_exprt old_array{this_symbol.symbol_expr()}; | ||
dereference_exprt new_array{local_symexpr}; |
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.
So in order to confirm that this is correct I had to read some more code, and the same is happening below: apologies that I'll come up with (almost) unrelated requests for fixes. For this one: local_symexpr
is declared as a const reference, but .symbol_expr
returns by value, so that's a reference to a temporary. Can you please remove the reference from local_symexpr
?
@@ -1623,7 +1623,7 @@ code_blockt java_bytecode_convert_methodt::convert_instructions( | |||
|
|||
const typecast_exprt pointer(op[0], java_array_type(statement[0])); | |||
|
|||
dereference_exprt array(pointer, pointer.type().subtype()); | |||
dereference_exprt array{pointer}; | |||
PRECONDITION(pointer.type().subtype().id() == ID_struct_tag); |
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 no idea why this PRECONDITION
is important right here, but if it for some reason needs to be enforced: PRECONDITION(array.type().id() == ID_struct_tag)
would be less opaque - but actually makes me wonder whether the name array
is a particularly good choice?
@@ -1623,7 +1623,7 @@ code_blockt java_bytecode_convert_methodt::convert_instructions( | |||
|
|||
const typecast_exprt pointer(op[0], java_array_type(statement[0])); | |||
|
|||
dereference_exprt array(pointer, pointer.type().subtype()); | |||
dereference_exprt array{pointer}; |
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.
We should actually use either std::move(pointer)
(and get rid of the const
) or just do array{typecast_exprt{op[0], java_array_type(statement[0])}}
. Applies here and in several other places.
@@ -1102,8 +1102,7 @@ void java_object_factoryt::array_primitive_init_code( | |||
|
|||
// *array_data_init = NONDET(TYPE [max_length_expr]); | |||
side_effect_expr_nondett nondet_data(array_type, location); | |||
const dereference_exprt data_pointer_deref( | |||
tmp_finite_array_pointer, array_type); | |||
const dereference_exprt data_pointer_deref{tmp_finite_array_pointer}; |
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.
Get rid of const
and use std::move(data_pointer_deref)
below.
@@ -1303,7 +1301,7 @@ void java_object_factoryt::gen_nondet_array_init( | |||
is_valid_java_array(struct_type), | |||
"Java struct array does not conform to expectations"); | |||
|
|||
dereference_exprt deref_expr(expr, expr.type().subtype()); | |||
dereference_exprt deref_expr(expr); |
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.
Braces (as introduced in all the other places)
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 knew I would forget them somewhere!
dereference_exprt(rhs, rhs.type().subtype())); | ||
else if(lhs.type().id() == ID_pointer) | ||
return value_assignments( | ||
dest, target, dereference_exprt{lhs}, dereference_exprt{rhs}); |
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.
Please add braces as this is (always was) a multi-line statement in the body of an if
.
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.
MT's suggestions are good, but this is also good to merge as-is in my opinion, so I'd say feel free to merge and follow up addressing those suggestions
@tautschnig Thank you for your suggestions, I'll try to find time to make a PR for them but I have a few higher priority tasks to get through first. |
@antlechner Oops, sorry, I should have posted on here: I think I've taken care of them in #4532. |
This PR removes some parameters to constructors that are not necessary. There is no functional change.
If you think the constructor for
plus_exprt
that takes two exprts and a typet should be deprecated or deleted, please let me know.