Skip to content

Commit b3c456f

Browse files
authored
Merge pull request #6543 from tautschnig/is_boolean
Consistently use exprt::is_boolean()
2 parents abd5181 + 882b295 commit b3c456f

37 files changed

+114
-128
lines changed

jbmc/src/java_bytecode/expr2java.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ std::string expr2javat::convert_constant(
175175
else
176176
return "false";
177177
}
178-
else if(src.type().id()==ID_bool)
178+
else if(src.is_boolean())
179179
{
180180
if(src.is_true())
181181
return "true";

src/analyses/guard_expr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ exprt guard_exprt::guard_expr(exprt expr) const
3737

3838
void guard_exprt::add(const exprt &expr)
3939
{
40-
PRECONDITION(expr.type().id() == ID_bool);
40+
PRECONDITION(expr.is_boolean());
4141

4242
if(is_false() || expr.is_true())
4343
return;

src/analyses/invariant_set.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ void invariant_sett::strengthen(const exprt &expr)
381381

382382
void invariant_sett::strengthen_rec(const exprt &expr)
383383
{
384-
if(expr.type().id()!=ID_bool)
384+
if(!expr.is_boolean())
385385
throw "non-Boolean argument to strengthen()";
386386

387387
#if 0
@@ -584,7 +584,7 @@ tvt invariant_sett::implies(const exprt &expr) const
584584

585585
tvt invariant_sett::implies_rec(const exprt &expr) const
586586
{
587-
if(expr.type().id()!=ID_bool)
587+
if(!expr.is_boolean())
588588
throw "implies: non-Boolean expression";
589589

590590
#if 0
@@ -696,7 +696,7 @@ void invariant_sett::get_bounds(unsigned a, boundst &bounds) const
696696

697697
void invariant_sett::nnf(exprt &expr, bool negate)
698698
{
699-
if(expr.type().id()!=ID_bool)
699+
if(!expr.is_boolean())
700700
throw "nnf: non-Boolean expression";
701701

702702
if(expr.is_true())

src/analyses/variable-sensitivity/abstract_environment.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,16 +262,15 @@ bool abstract_environmentt::assume(const exprt &expr, const namespacet &ns)
262262
// We should only attempt to assume Boolean things
263263
// This should be enforced by the well-structured-ness of the
264264
// goto-program and the way assume is used.
265-
PRECONDITION(expr.type().id() == ID_bool);
265+
PRECONDITION(expr.is_boolean());
266266

267267
auto simplified = simplify_expr(expr, ns);
268268
auto assumption = do_assume(simplified, ns);
269269

270270
if(assumption.id() != ID_nil) // I.E. actually a value
271271
{
272272
// Should be of the right type
273-
INVARIANT(
274-
assumption.type().id() == ID_bool, "simplification preserves type");
273+
INVARIANT(assumption.is_boolean(), "simplification preserves type");
275274

276275
if(assumption.is_false())
277276
{

src/ansi-c/c_typecheck_expr.cpp

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ void c_typecheck_baset::typecheck_expr_main(exprt &expr)
431431
// This is one of the few places where it's detectable
432432
// that we are using "bool" for boolean operators instead
433433
// of "int". We convert for this reason.
434-
if(op.type().id() == ID_bool)
434+
if(op.is_boolean())
435435
op = typecast_exprt(op, signed_int_type());
436436

437437
irept::subt &generic_associations=
@@ -960,7 +960,7 @@ void c_typecheck_baset::typecheck_expr_sizeof(exprt &expr)
960960
// This is one of the few places where it's detectable
961961
// that we are using "bool" for boolean operators instead
962962
// of "int". We convert for this reason.
963-
if(op.type().id() == ID_bool)
963+
if(op.is_boolean())
964964
type = signed_int_type();
965965
else
966966
type = op.type();
@@ -1102,7 +1102,7 @@ void c_typecheck_baset::typecheck_expr_typecast(exprt &expr)
11021102
// This is one of the few places where it's detectable
11031103
// that we are using "bool" for boolean operators instead
11041104
// of "int". We convert for this reason.
1105-
if(op.type().id() == ID_bool)
1105+
if(op.is_boolean())
11061106
op = typecast_exprt(op, signed_int_type());
11071107

11081108
// we need to find a member with the right type
@@ -1718,7 +1718,7 @@ void c_typecheck_baset::typecheck_expr_address_of(exprt &expr)
17181718
throw 0;
17191719
}
17201720

1721-
if(op.type().id() == ID_bool)
1721+
if(op.is_boolean())
17221722
{
17231723
error().source_location = expr.source_location();
17241724
error() << "cannot take address of a single bit" << eom;
@@ -4387,7 +4387,7 @@ void c_typecheck_baset::typecheck_side_effect_assignment(
43874387
{
43884388
implicit_typecast_arithmetic(op0, op1);
43894389
if(
4390-
op1.type().id() == ID_bool || op1.type().id() == ID_c_bool ||
4390+
op1.is_boolean() || op1.type().id() == ID_c_bool ||
43914391
op1.type().id() == ID_c_enum_tag || op1.type().id() == ID_unsignedbv ||
43924392
op1.type().id() == ID_signedbv || op1.type().id() == ID_c_bit_field)
43934393
{
@@ -4453,7 +4453,7 @@ void c_typecheck_baset::typecheck_side_effect_assignment(
44534453
implicit_typecast_arithmetic(op1);
44544454

44554455
if(
4456-
is_number(op1.type()) || op1.type().id() == ID_bool ||
4456+
is_number(op1.type()) || op1.is_boolean() ||
44574457
op1.type().id() == ID_c_bool || op1.type().id() == ID_c_enum_tag)
44584458
{
44594459
op1 = typecast_exprt(op1, o_type0);
@@ -4464,22 +4464,24 @@ void c_typecheck_baset::typecheck_side_effect_assignment(
44644464
o_type0.id()==ID_c_bool)
44654465
{
44664466
implicit_typecast_arithmetic(op0, op1);
4467-
if(op1.type().id()==ID_bool ||
4468-
op1.type().id()==ID_c_bool ||
4469-
op1.type().id()==ID_c_enum_tag ||
4470-
op1.type().id()==ID_unsignedbv ||
4471-
op1.type().id()==ID_signedbv)
4467+
if(
4468+
op1.is_boolean() || op1.type().id() == ID_c_bool ||
4469+
op1.type().id() == ID_c_enum_tag || op1.type().id() == ID_unsignedbv ||
4470+
op1.type().id() == ID_signedbv)
4471+
{
44724472
return;
4473+
}
44734474
}
44744475
else
44754476
{
44764477
implicit_typecast_arithmetic(op0, op1);
44774478

4478-
if(is_number(op1.type()) ||
4479-
op1.type().id()==ID_bool ||
4480-
op1.type().id()==ID_c_bool ||
4481-
op1.type().id()==ID_c_enum_tag)
4479+
if(
4480+
is_number(op1.type()) || op1.is_boolean() ||
4481+
op1.type().id() == ID_c_bool || op1.type().id() == ID_c_enum_tag)
4482+
{
44824483
return;
4484+
}
44834485
}
44844486
}
44854487

src/ansi-c/padding.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,7 @@ static void add_padding_msvc(struct_typet &type, const namespacet &ns)
193193
const auto width = to_c_bit_field_type(it->type()).get_width();
194194
bit_field_bits += width;
195195
}
196-
else if(
197-
it->type().id() == ID_bool && underlying_bits == config.ansi_c.char_width)
196+
else if(it->is_boolean() && underlying_bits == config.ansi_c.char_width)
198197
{
199198
++bit_field_bits;
200199
}
@@ -242,7 +241,7 @@ static void add_padding_msvc(struct_typet &type, const namespacet &ns)
242241
const auto width = to_c_bit_field_type(it->type()).get_width();
243242
bit_field_bits += width;
244243
}
245-
else if(it->type().id() == ID_bool)
244+
else if(it->is_boolean())
246245
{
247246
underlying_bits = config.ansi_c.char_width;
248247
++bit_field_bits;
@@ -304,7 +303,7 @@ static void add_padding_gcc(struct_typet &type, const namespacet &ns)
304303
const std::size_t width = to_c_bit_field_type(it->type()).get_width();
305304
bit_field_bits+=width;
306305
}
307-
else if(it->type().id() == ID_bool)
306+
else if(it->is_boolean())
308307
{
309308
++bit_field_bits;
310309
}

src/cpp/cpp_typecheck_conversions.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ bool cpp_typecheckt::standard_conversion_integral_promotion(
221221
return true;
222222
}
223223

224-
if(expr.type().id() == ID_bool || expr.type().id() == ID_c_bool)
224+
if(expr.is_boolean() || expr.type().id() == ID_c_bool)
225225
{
226226
new_expr = typecast_exprt(expr, int_type);
227227
return true;
@@ -308,7 +308,7 @@ bool cpp_typecheckt::standard_conversion_integral_conversion(
308308

309309
if(
310310
expr.type().id() != ID_signedbv && expr.type().id() != ID_unsignedbv &&
311-
expr.type().id() != ID_c_bool && expr.type().id() != ID_bool &&
311+
expr.type().id() != ID_c_bool && !expr.is_boolean() &&
312312
expr.type().id() != ID_c_enum_tag)
313313
{
314314
return false;
@@ -640,7 +640,7 @@ bool cpp_typecheckt::standard_conversion_boolean(
640640

641641
if(
642642
expr.type().id() != ID_signedbv && expr.type().id() != ID_unsignedbv &&
643-
expr.type().id() != ID_pointer && expr.type().id() != ID_bool &&
643+
expr.type().id() != ID_pointer && !expr.is_boolean() &&
644644
expr.type().id() != ID_c_enum_tag)
645645
{
646646
return false;
@@ -1838,7 +1838,7 @@ bool cpp_typecheckt::reinterpret_typecast(
18381838

18391839
if(
18401840
(e.type().id() == ID_unsignedbv || e.type().id() == ID_signedbv ||
1841-
e.type().id() == ID_c_bool || e.type().id() == ID_bool) &&
1841+
e.type().id() == ID_c_bool || e.is_boolean()) &&
18421842
type.id() == ID_pointer && !is_reference(type))
18431843
{
18441844
// integer to pointer

src/goto-instrument/accelerate/disjunctive_polynomial_acceleration.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ bool disjunctive_polynomial_accelerationt::accelerate(
8888
polynomialt poly;
8989
exprt target=*it;
9090

91-
if(it->type().id()==ID_bool)
91+
if(it->is_boolean())
9292
{
9393
// Hack: don't try to accelerate booleans.
9494
continue;
@@ -150,7 +150,7 @@ bool disjunctive_polynomial_accelerationt::accelerate(
150150
std::cout << "Trying to accelerate " << format(*it) << '\n';
151151
#endif
152152

153-
if(it->type().id()==ID_bool)
153+
if(it->is_boolean())
154154
{
155155
// Hack: don't try to accelerate booleans.
156156
accelerator.dirty_vars.insert(*it);

src/goto-instrument/cover_util.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Author: Daniel Kroening
1313

1414
bool is_condition(const exprt &src)
1515
{
16-
if(src.type().id() != ID_bool)
16+
if(!src.is_boolean())
1717
return false;
1818

1919
// conditions are 'atomic predicates'
@@ -73,7 +73,7 @@ void collect_decisions_rec(const exprt &src, std::set<exprt> &dest)
7373
return;
7474
}
7575

76-
if(src.type().id() == ID_bool)
76+
if(src.is_boolean())
7777
{
7878
if(src.is_constant())
7979
{

src/goto-programs/goto_program.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1011,7 +1011,7 @@ class goto_programt
10111011
const exprt &_cond,
10121012
const source_locationt &l = source_locationt::nil())
10131013
{
1014-
PRECONDITION(_cond.type().id() == ID_bool);
1014+
PRECONDITION(_cond.is_boolean());
10151015
return instructiont(
10161016
static_cast<const goto_instruction_codet &>(get_nil_irep()),
10171017
l,

0 commit comments

Comments
 (0)