-
Notifications
You must be signed in to change notification settings - Fork 274
Construct array_exprt in a non-deprecated way [blocks: #3768] #3771
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -122,7 +122,7 @@ exprt expr_initializert<nondet>::expr_initializer_rec( | |
{ | ||
// we initialize this with an empty array | ||
|
||
array_exprt value(array_type); | ||
array_exprt value({}, array_type); | ||
value.type().id(ID_array); | ||
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. I don't see why this is necessary 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. We could arguably make the no-operands-constructor non-deprecated. Would that seem better? 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. So I'm still in two minds about this. I see the following options:
Comments would be appreciated. |
||
value.type().set(ID_size, from_integer(0, size_type())); | ||
value.add_source_location()=source_location; | ||
|
@@ -157,7 +157,7 @@ exprt expr_initializert<nondet>::expr_initializer_rec( | |
if(*array_size < 0) | ||
return nil_exprt(); | ||
|
||
array_exprt value(array_type); | ||
array_exprt value({}, array_type); | ||
value.operands().resize(numeric_cast_v<std::size_t>(*array_size), tmpval); | ||
value.add_source_location()=source_location; | ||
return std::move(value); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1765,6 +1765,11 @@ class array_exprt : public multi_ary_exprt | |
: multi_ary_exprt(ID_array, _type) | ||
{ | ||
} | ||
|
||
array_exprt(operandst &&_operands, const array_typet &_type) | ||
: multi_ary_exprt(ID_array, std::move(_operands), _type) | ||
{ | ||
} | ||
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. This could have been a separate first commit |
||
}; | ||
|
||
/// \brief Cast an exprt to an \ref array_exprt | ||
|
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.
Not sure about this one -- somehow an empty array with a correct type (seen many times below) seems considerably safer than this partially-constructed thing. If we're going to partially construct something, we should probably use a constructor with that express purpose, rather than pretending we're doing it safely?
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.
The language front-ends will always remain a bit weird. I'm not sure what the best option is - we could also do
exprt values(ID_array);
to make very clear we are not building anything like a complete expression here.