Skip to content

Commit 1d5a075

Browse files
authored
Merge pull request #7460 from tautschnig/cleanup/expr2c-output
expr2c/{r,w,rw}_ok: add a dedicated method
2 parents 019952e + 3ef5378 commit 1d5a075

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

src/ansi-c/expr2c.cpp

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3554,6 +3554,24 @@ std::string expr2ct::convert_bitreverse(const bitreverse_exprt &src)
35543554
return convert_norep(src, precedence);
35553555
}
35563556

3557+
std::string expr2ct::convert_r_or_w_ok(const r_or_w_ok_exprt &src)
3558+
{
3559+
std::string dest = src.id() == ID_r_ok ? "R_OK"
3560+
: src.id() == ID_w_ok ? "W_OK"
3561+
: "RW_OK";
3562+
3563+
dest += '(';
3564+
3565+
unsigned p;
3566+
dest += convert_with_precedence(src.pointer(), p);
3567+
dest += ", ";
3568+
dest += convert_with_precedence(src.size(), p);
3569+
3570+
dest += ')';
3571+
3572+
return dest;
3573+
}
3574+
35573575
std::string expr2ct::convert_with_precedence(
35583576
const exprt &src,
35593577
unsigned &precedence)
@@ -3963,6 +3981,9 @@ std::string expr2ct::convert_with_precedence(
39633981
else if(src.id() == ID_bitreverse)
39643982
return convert_bitreverse(to_bitreverse_expr(src));
39653983

3984+
else if(src.id() == ID_r_ok || src.id() == ID_w_ok || src.id() == ID_rw_ok)
3985+
return convert_r_or_w_ok(to_r_or_w_ok_expr(src));
3986+
39663987
auto function_string_opt = convert_function(src);
39673988
if(function_string_opt.has_value())
39683989
return *function_string_opt;
@@ -4018,9 +4039,6 @@ optionalt<std::string> expr2ct::convert_function(const exprt &src)
40184039
{ID_loop_entry, CPROVER_PREFIX "loop_entry"},
40194040
{ID_saturating_minus, CPROVER_PREFIX "saturating_minus"},
40204041
{ID_saturating_plus, CPROVER_PREFIX "saturating_plus"},
4021-
{ID_r_ok, "R_OK"},
4022-
{ID_w_ok, "W_OK"},
4023-
{ID_rw_ok, "RW_OK"},
40244042
{ID_width, "WIDTH"},
40254043
};
40264044

src/ansi-c/expr2c_class.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Author: Daniel Kroening, [email protected]
2626
class annotated_pointer_constant_exprt;
2727
class qualifierst;
2828
class namespacet;
29+
class r_or_w_ok_exprt;
2930

3031
class expr2ct
3132
{
@@ -281,6 +282,8 @@ class expr2ct
281282

282283
std::string convert_conditional_target_group(const exprt &src);
283284
std::string convert_bitreverse(const bitreverse_exprt &src);
285+
286+
std::string convert_r_or_w_ok(const r_or_w_ok_exprt &src);
284287
};
285288

286289
#endif // CPROVER_ANSI_C_EXPR2C_CLASS_H

0 commit comments

Comments
 (0)