Skip to content

Commit 82ab0ec

Browse files
author
thk123
committed
Extracted out the converting constant boolean expressions
This allows other implementations of what constant boolean expressions should be written as.
1 parent 9670d27 commit 82ab0ec

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

src/ansi-c/expr2c.cpp

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2216,11 +2216,7 @@ std::string expr2ct::convert_constant(
22162216
}
22172217
else if(type.id()==ID_bool)
22182218
{
2219-
// C doesn't really have these
2220-
if(src.is_true())
2221-
dest="TRUE";
2222-
else
2223-
dest="FALSE";
2219+
dest = convert_constant_bool(src.is_true());
22242220
}
22252221
else if(type.id()==ID_unsignedbv ||
22262222
type.id()==ID_signedbv ||
@@ -2236,11 +2232,7 @@ std::string expr2ct::convert_constant(
22362232

22372233
if(type.id()==ID_c_bool)
22382234
{
2239-
// C doesn't really have these
2240-
if(int_value!=0)
2241-
dest="TRUE";
2242-
else
2243-
dest="FALSE";
2235+
dest = convert_constant_bool(int_value != 0);
22442236
}
22452237
else if(type==char_type() && type!=signed_int_type() && type!=unsigned_int_type())
22462238
{
@@ -2393,6 +2385,28 @@ std::string expr2ct::convert_constant(
23932385

23942386
/*******************************************************************\
23952387
2388+
Function: expr2ct::convert_constant_bool
2389+
2390+
Inputs:
2391+
boolean_value - The value of the constant bool expression
2392+
2393+
Outputs: Returns a C-like representation of the boolean value,
2394+
e.g. TRUE or FALSE.
2395+
2396+
Purpose: To get the C-like representation of a given boolean value.
2397+
2398+
\*******************************************************************/
2399+
std::string expr2ct::convert_constant_bool(bool boolean_value)
2400+
{
2401+
// C doesn't really have these
2402+
if(boolean_value)
2403+
return "TRUE";
2404+
else
2405+
return "FALSE";
2406+
}
2407+
2408+
/*******************************************************************\
2409+
23962410
Function: expr2ct::convert_struct
23972411
23982412
Inputs:

src/ansi-c/expr2c_class.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ class expr2ct
209209
std::string convert_object_descriptor(const exprt &src, unsigned &precedence);
210210
std::string convert_literal(const exprt &src, unsigned &precedence);
211211
virtual std::string convert_constant(const constant_exprt &src, unsigned &precedence);
212+
virtual std::string convert_constant_bool(bool boolean_value);
212213

213214
std::string convert_norep(const exprt &src, unsigned &precedence);
214215

0 commit comments

Comments
 (0)