Skip to content

expr2c/{r,w,rw}_ok: add a dedicated method #7460

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions src/ansi-c/expr2c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3554,6 +3554,24 @@ std::string expr2ct::convert_bitreverse(const bitreverse_exprt &src)
return convert_norep(src, precedence);
}

std::string expr2ct::convert_r_or_w_ok(const r_or_w_ok_exprt &src)
{
std::string dest = src.id() == ID_r_ok ? "R_OK"
: src.id() == ID_w_ok ? "W_OK"
: "RW_OK";

dest += '(';

unsigned p;
dest += convert_with_precedence(src.pointer(), p);
dest += ", ";
dest += convert_with_precedence(src.size(), p);

dest += ')';

return dest;
}

std::string expr2ct::convert_with_precedence(
const exprt &src,
unsigned &precedence)
Expand Down Expand Up @@ -3963,6 +3981,9 @@ std::string expr2ct::convert_with_precedence(
else if(src.id() == ID_bitreverse)
return convert_bitreverse(to_bitreverse_expr(src));

else if(src.id() == ID_r_ok || src.id() == ID_w_ok || src.id() == ID_rw_ok)
return convert_r_or_w_ok(to_r_or_w_ok_expr(src));

auto function_string_opt = convert_function(src);
if(function_string_opt.has_value())
return *function_string_opt;
Expand Down Expand Up @@ -4018,9 +4039,6 @@ optionalt<std::string> expr2ct::convert_function(const exprt &src)
{ID_loop_entry, CPROVER_PREFIX "loop_entry"},
{ID_saturating_minus, CPROVER_PREFIX "saturating_minus"},
{ID_saturating_plus, CPROVER_PREFIX "saturating_plus"},
{ID_r_ok, "R_OK"},
{ID_w_ok, "W_OK"},
{ID_rw_ok, "RW_OK"},
{ID_width, "WIDTH"},
};

Expand Down
3 changes: 3 additions & 0 deletions src/ansi-c/expr2c_class.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Author: Daniel Kroening, [email protected]
class annotated_pointer_constant_exprt;
class qualifierst;
class namespacet;
class r_or_w_ok_exprt;

class expr2ct
{
Expand Down Expand Up @@ -281,6 +282,8 @@ class expr2ct

std::string convert_conditional_target_group(const exprt &src);
std::string convert_bitreverse(const bitreverse_exprt &src);

std::string convert_r_or_w_ok(const r_or_w_ok_exprt &src);
};

#endif // CPROVER_ANSI_C_EXPR2C_CLASS_H