Skip to content

rename is_lvalue -> is_assignable #6378

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
Oct 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/analyses/variable-sensitivity/abstract_environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -711,14 +711,14 @@ exprt assume_eq_unbounded(
const left_and_right_valuest &operands,
const namespacet &ns)
{
if(operands.left->is_top() && is_lvalue(operands.lhs))
if(operands.left->is_top() && is_assignable(operands.lhs))
{
// TOP == x
auto constrained = std::make_shared<interval_abstract_valuet>(
operands.right_interval(), env, ns);
prune_assign(env, operands.left, operands.lhs, constrained, ns);
}
if(operands.right->is_top() && is_lvalue(operands.rhs))
if(operands.right->is_top() && is_assignable(operands.rhs))
{
// x == TOP
auto constrained = std::make_shared<interval_abstract_valuet>(
Expand Down Expand Up @@ -746,9 +746,9 @@ exprt assume_eq(
if(meet->is_bottom())
return false_exprt();

if(is_lvalue(operands.lhs))
if(is_assignable(operands.lhs))
prune_assign(env, operands.left, operands.lhs, meet, ns);
if(is_lvalue(operands.rhs))
if(is_assignable(operands.rhs))
prune_assign(env, operands.right, operands.rhs, meet, ns);
return true_exprt();
}
Expand Down Expand Up @@ -781,7 +781,7 @@ exprt assume_less_than_unbounded(
const left_and_right_valuest &operands,
const namespacet &ns)
{
if(operands.left->is_top() && is_lvalue(operands.lhs))
if(operands.left->is_top() && is_assignable(operands.lhs))
{
// TOP < x, so prune range is min->right.upper
auto pruned_expr = constant_interval_exprt(
Expand All @@ -792,7 +792,7 @@ exprt assume_less_than_unbounded(
std::make_shared<interval_abstract_valuet>(pruned_expr, env, ns);
prune_assign(env, operands.left, operands.lhs, constrained, ns);
}
if(operands.right->is_top() && is_lvalue(operands.rhs))
if(operands.right->is_top() && is_assignable(operands.rhs))
{
// x < TOP, so prune range is left.lower->max
auto pruned_expr = constant_interval_exprt(
Expand Down Expand Up @@ -830,15 +830,15 @@ exprt assume_less_than(
auto result = env.eval(reduced_le_expr, ns)->to_constant();
if(result.is_true())
{
if(is_lvalue(operands.lhs))
if(is_assignable(operands.lhs))
{
auto pruned_upper = constant_interval_exprt::get_min(
left_interval.get_upper(), right_upper);
auto constrained =
as_value(operands.left)->constrain(left_lower, pruned_upper);
prune_assign(env, operands.left, operands.lhs, constrained, ns);
}
if(is_lvalue(operands.rhs))
if(is_assignable(operands.rhs))
{
auto pruned_lower = constant_interval_exprt::get_max(
left_lower, right_interval.get_lower());
Expand Down
8 changes: 4 additions & 4 deletions src/goto-programs/builtin_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ exprt make_va_list(const exprt &expr)
if(result.id() == ID_address_of)
{
const auto &address_of_expr = to_address_of_expr(result);
if(is_lvalue(address_of_expr.object()))
if(is_assignable(address_of_expr.object()))
result = address_of_expr.object();
}

Expand Down Expand Up @@ -1156,7 +1156,7 @@ void goto_convertt::do_function_call_symbol(
exprt dest_expr=make_va_list(arguments[0]);
const typecast_exprt src_expr(arguments[1], dest_expr.type());

if(!is_lvalue(dest_expr))
if(!is_assignable(dest_expr))
{
error().source_location=dest_expr.find_source_location();
error() << "va_copy argument expected to be lvalue" << eom;
Expand All @@ -1179,7 +1179,7 @@ void goto_convertt::do_function_call_symbol(

exprt dest_expr=make_va_list(arguments[0]);

if(!is_lvalue(dest_expr))
if(!is_assignable(dest_expr))
{
error().source_location=dest_expr.find_source_location();
error() << "va_start argument expected to be lvalue" << eom;
Expand Down Expand Up @@ -1214,7 +1214,7 @@ void goto_convertt::do_function_call_symbol(

exprt dest_expr=make_va_list(arguments[0]);

if(!is_lvalue(dest_expr))
if(!is_assignable(dest_expr))
{
error().source_location=dest_expr.find_source_location();
error() << "va_end argument expected to be lvalue" << eom;
Expand Down
7 changes: 4 additions & 3 deletions src/util/expr_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,20 @@ Author: Daniel Kroening, [email protected]
#include "pointer_expr.h"
#include "std_expr.h"

bool is_lvalue(const exprt &expr)
bool is_assignable(const exprt &expr)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this perhaps be moved to goto-programs? The use in replace_symbol obviously conflicts with that, but some follow-up cleanup may be necessary.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes; there may well be a need to make copies of this function for particular uses. I'd see this as an orthogonal question to the renaming done here.

{
if(expr.id() == ID_index)
return is_lvalue(to_index_expr(expr).array());
return is_assignable(to_index_expr(expr).array());
else if(expr.id() == ID_member)
return is_lvalue(to_member_expr(expr).compound());
return is_assignable(to_member_expr(expr).compound());
else if(expr.id() == ID_dereference)
return true;
else if(expr.id() == ID_symbol)
return true;
else
return false;
}

exprt make_binary(const exprt &expr)
{
const exprt::operandst &operands=expr.operands();
Expand Down
8 changes: 6 additions & 2 deletions src/util/expr_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@ class if_exprt;
class typet;
class namespacet;

/// Returns true iff the argument is (syntactically) an lvalue.
bool is_lvalue(const exprt &expr);
/// Returns true iff the argument is one of the following:
/// * a symbol
/// * a dereference
/// * an array element
/// * a struct member
bool is_assignable(const exprt &);

/// splits an expression with >=3 operands into nested binary expressions
exprt make_binary(const exprt &);
Expand Down
2 changes: 1 addition & 1 deletion src/util/replace_symbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ bool address_of_aware_replace_symbolt::replace_symbol_expr(
if(unchecked_replace_symbolt::replace_symbol_expr(s_copy))
return true;

if(require_lvalue && !is_lvalue(s_copy))
if(require_lvalue && !is_assignable(s_copy))
return true;

// Note s_copy is no longer a symbol_exprt due to the replace operation,
Expand Down