Skip to content

Commit 382b80b

Browse files
mgudemannpeterschrammel
authored andcommitted
direct support for ID_c_bool in exprt (#438)
The `is_true()` / `is_false()` functions in `exprt` currently support only the `ID_bool` type. In Java, Boolean values are represented as `ID_c_bool` due to the internal JVM usage of integers. Adding this support here seems easier than having special treatment in `java_bytecode`.
1 parent 12a79ab commit 382b80b

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

src/util/expr.cpp

+20-6
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,18 @@ Function: exprt::is_true
245245

246246
bool exprt::is_true() const
247247
{
248-
return is_constant() &&
249-
type().id()==ID_bool &&
250-
get(ID_value)!=ID_false;
248+
if(is_constant())
249+
{
250+
if(type().id()==ID_bool)
251+
return get(ID_value)!=ID_false;
252+
else if(type().id()==ID_c_bool)
253+
{
254+
mp_integer i;
255+
to_integer(*this, i);
256+
return i!=mp_integer(0);
257+
}
258+
}
259+
return false;
251260
}
252261

253262
/*******************************************************************\
@@ -264,9 +273,14 @@ Function: exprt::is_false
264273

265274
bool exprt::is_false() const
266275
{
267-
return is_constant() &&
268-
type().id()==ID_bool &&
269-
get(ID_value)==ID_false;
276+
if(is_constant())
277+
{
278+
if(type().id()==ID_bool)
279+
return get(ID_value)==ID_false;
280+
else if(type().id()==ID_c_bool)
281+
return !is_true();
282+
}
283+
return false;
270284
}
271285

272286
/*******************************************************************\

0 commit comments

Comments
 (0)