Skip to content

Commit 49b0141

Browse files
author
thk123
committed
Refactor out method for generating a struct expression
The extracted method gives the option for the caller to exclude padding members (which don't exist in the C code and are generated for GOTO to provide a more accurate representation of the struct).
1 parent e5bf74b commit 49b0141

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/ansi-c/expr2c.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2337,6 +2337,31 @@ Function: expr2ct::convert_struct
23372337
std::string expr2ct::convert_struct(
23382338
const exprt &src,
23392339
unsigned &precedence)
2340+
{
2341+
return convert_struct(src, precedence, true);
2342+
}
2343+
2344+
/*******************************************************************\
2345+
2346+
Function: expr2ct::convert_struct
2347+
2348+
Inputs:
2349+
src - The struct declaration expression
2350+
precedence
2351+
include_padding_members - Should the generated C code
2352+
include the padding members added
2353+
to structs for GOTOs benifit
2354+
2355+
Outputs: A string representation of the struct expression
2356+
2357+
Purpose: To generate a C-like string representing a struct. Can optionally
2358+
include the padding parameters.
2359+
2360+
\*******************************************************************/
2361+
std::string expr2ct::convert_struct(
2362+
const exprt &src,
2363+
unsigned &precedence,
2364+
bool include_padding_members)
23402365
{
23412366
const typet full_type=ns.follow(src.type());
23422367

@@ -2368,6 +2393,12 @@ std::string expr2ct::convert_struct(
23682393
if(o_it->type().id()==ID_code)
23692394
continue;
23702395

2396+
if(c_it->get_is_padding() && !include_padding_members)
2397+
{
2398+
++o_it;
2399+
continue;
2400+
}
2401+
23712402
if(first)
23722403
first=false;
23732404
else

src/ansi-c/expr2c_class.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,11 @@ class expr2ct
209209
std::string convert_designated_initializer(const exprt &src, unsigned &precedence);
210210
std::string convert_concatenation(const exprt &src, unsigned &precedence);
211211
std::string convert_sizeof(const exprt &src, unsigned &precedence);
212+
213+
std::string convert_struct(
214+
const exprt &src,
215+
unsigned &precedence,
216+
bool include_padding_members);
212217
};
213218

214219
#endif // CPROVER_ANSI_C_EXPR2C_CLASS_H

0 commit comments

Comments
 (0)