Skip to content

Commit c2813b7

Browse files
authored
Merge pull request #6542 from tautschnig/is_constant
Consistently use exprt::is_constant()
2 parents b3c456f + 5eddb4c commit c2813b7

File tree

75 files changed

+163
-192
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+163
-192
lines changed

jbmc/src/java_bytecode/expr2java.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ std::string expr2javat::convert_with_precedence(
427427
{
428428
return '"' + MetaString(id2string(literal->value())) + '"';
429429
}
430-
else if(src.id()==ID_constant)
430+
else if(src.is_constant())
431431
return convert_constant(to_constant_expr(src), precedence=16);
432432
else
433433
return expr2ct::convert_with_precedence(src, precedence);

jbmc/src/java_bytecode/java_bytecode_convert_method.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,8 +1447,7 @@ java_bytecode_convert_methodt::convert_instructions(const methodt &method)
14471447
{
14481448
CHECK_RETURN(results.size() == 1);
14491449
DATA_INVARIANT(
1450-
arg0.id()==ID_constant,
1451-
"ipush argument expected to be constant");
1450+
arg0.is_constant(), "ipush argument expected to be constant");
14521451
results[0] = typecast_exprt::conditional_cast(arg0, java_int_type());
14531452
}
14541453
else if(bytecode == patternt("if_?cmp??"))

jbmc/src/java_bytecode/java_bytecode_language.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ static exprt get_ldc_result(
581581
else
582582
{
583583
INVARIANT(
584-
ldc_arg0.id() == ID_constant,
584+
ldc_arg0.is_constant(),
585585
"ldc argument should be constant, string literal or class literal");
586586
return ldc_arg0;
587587
}

jbmc/src/java_bytecode/java_trace_validation.cpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -104,19 +104,15 @@ bool check_struct_structure(const struct_exprt &expr)
104104
{
105105
return false;
106106
}
107-
if(
108-
expr.operands().size() > 1 && std::any_of(
109-
++expr.operands().begin(),
110-
expr.operands().end(),
111-
[&](const exprt &operand) {
112-
return operand.id() != ID_constant &&
113-
operand.id() !=
114-
ID_annotated_pointer_constant;
115-
}))
116-
{
117-
return false;
118-
}
119-
return true;
107+
108+
return expr.operands().size() == 1 ||
109+
std::all_of(
110+
std::next(expr.operands().begin()),
111+
expr.operands().end(),
112+
[&](const exprt &operand) {
113+
return can_cast_expr<constant_exprt>(operand) ||
114+
can_cast_expr<annotated_pointer_constant_exprt>(operand);
115+
});
120116
}
121117

122118
bool check_address_structure(const address_of_exprt &address)

jbmc/unit/java_bytecode/goto-programs/remove_virtual_functions_without_fallback.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ exprt resolve_classid_test(
3333

3434
const auto &expr_binary = to_binary_expr(expr);
3535

36-
if(
37-
expr_binary.op0().id() == ID_constant &&
38-
expr_binary.op1().id() != ID_constant)
36+
if(expr_binary.op0().is_constant() && !expr_binary.op1().is_constant())
3937
{
4038
binary_exprt swapped = expr_binary;
4139
std::swap(swapped.op0(), swapped.op1());
@@ -46,7 +44,7 @@ exprt resolve_classid_test(
4644
expr_binary.op0().id() == ID_member &&
4745
to_member_expr(expr_binary.op0()).get_component_name() ==
4846
"@class_identifier" &&
49-
expr_binary.op1().id() == ID_constant &&
47+
expr_binary.op1().is_constant() &&
5048
expr_binary.op1().type().id() == ID_string)
5149
{
5250
binary_exprt resolved = expr_binary;

jbmc/unit/java_bytecode/java_virtual_functions/virtual_functions.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ void check_function_call(
2222
const irep_idt &function_name,
2323
const goto_programt::targetst &targets)
2424
{
25-
REQUIRE(eq_expr.op0().id() == ID_constant);
25+
REQUIRE(eq_expr.op0().is_constant());
2626
REQUIRE(eq_expr.op0().type().id() == ID_string);
2727
REQUIRE(to_constant_expr(eq_expr.op0()).get_value() == class_name);
2828

@@ -99,8 +99,9 @@ SCENARIO(
9999
equal_exprt eq_expr1 =
100100
to_equal_expr(disjunction.op1());
101101

102-
if(eq_expr0.op0().id() == ID_constant &&
103-
to_constant_expr(eq_expr0.op0()).get_value() == "java::O")
102+
if(
103+
eq_expr0.op0().is_constant() &&
104+
to_constant_expr(eq_expr0.op0()).get_value() == "java::O")
104105
{
105106
// Allow either order of the D and O comparisons:
106107
std::swap(eq_expr0, eq_expr1);

src/analyses/constant_propagator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,7 @@ void constant_propagator_ait::replace(
777777

778778
if(!constant_propagator_domaint::partial_evaluate(d.values, rhs, ns))
779779
{
780-
if(rhs.id() == ID_constant)
780+
if(rhs.is_constant())
781781
rhs.add_source_location() = it->assign_lhs().source_location();
782782
}
783783
}

src/analyses/interval_domain.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ void interval_domaint::assume_rec(
272272
<< from_expr(rhs) << "\n";
273273
#endif
274274

275-
if(lhs.id()==ID_symbol && rhs.id()==ID_constant)
275+
if(lhs.id() == ID_symbol && rhs.is_constant())
276276
{
277277
irep_idt lhs_identifier=to_symbol_expr(lhs).get_identifier();
278278

@@ -297,7 +297,7 @@ void interval_domaint::assume_rec(
297297
make_bottom();
298298
}
299299
}
300-
else if(lhs.id()==ID_constant && rhs.id()==ID_symbol)
300+
else if(lhs.is_constant() && rhs.id() == ID_symbol)
301301
{
302302
irep_idt rhs_identifier=to_symbol_expr(rhs).get_identifier();
303303

src/analyses/local_bitvector_analysis.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ local_bitvector_analysist::flagst local_bitvector_analysist::get_rec(
113113
const exprt &rhs,
114114
points_tot &loc_info_src)
115115
{
116-
if(rhs.id()==ID_constant)
116+
if(rhs.is_constant())
117117
{
118118
if(rhs.is_zero())
119119
return flagst::mk_null();

src/analyses/local_may_alias.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ void local_may_aliast::get_rec(
169169
const exprt &rhs,
170170
const loc_infot &loc_info_src) const
171171
{
172-
if(rhs.id()==ID_constant)
172+
if(rhs.is_constant())
173173
{
174174
if(rhs.is_zero())
175175
dest.insert(objects.number(exprt(ID_null_object)));

0 commit comments

Comments
 (0)