Skip to content

Commit 31f77d5

Browse files
authored
Merge pull request #4322 from diffblue/introduce_code_bodyt
introduce code_bodyt
2 parents 6f3ced1 + 9a3d321 commit 31f77d5

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed

src/util/irep_ids.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,7 @@ IREP_ID_TWO(C_quoted, #quoted)
721721
IREP_ID_ONE(to_member)
722722
IREP_ID_ONE(pointer_to_member)
723723
IREP_ID_ONE(tuple)
724+
IREP_ID_ONE(function_body)
724725

725726
// Projects depending on this code base that wish to extend the list of
726727
// available ids should provide a file local_irep_ids.def in their source tree

src/util/std_code.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,25 @@ code_blockt create_fatal_assertion(
145145

146146
return result;
147147
}
148+
149+
std::vector<irep_idt> code_function_bodyt::get_parameter_identifiers() const
150+
{
151+
const auto &sub = find(ID_parameters).get_sub();
152+
std::vector<irep_idt> result;
153+
result.reserve(sub.size());
154+
for(const auto &s : sub)
155+
result.push_back(s.get(ID_identifier));
156+
return result;
157+
}
158+
159+
void code_function_bodyt::set_parameter_identifiers(
160+
const std::vector<irep_idt> &parameter_identifiers)
161+
{
162+
auto &sub = add(ID_parameters).get_sub();
163+
sub.reserve(parameter_identifiers.size());
164+
for(const auto &id : parameter_identifiers)
165+
{
166+
sub.push_back(irept(ID_parameter));
167+
sub.back().set(ID_identifier, id);
168+
}
169+
}

src/util/std_code.h

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2490,4 +2490,54 @@ inline code_try_catcht &to_code_try_catch(codet &code)
24902490
return static_cast<code_try_catcht &>(code);
24912491
}
24922492

2493+
/// This class is used to interface between a language frontend
2494+
/// and goto-convert -- it communicates the identifiers of the parameters
2495+
/// of a function or method
2496+
class code_function_bodyt : public codet
2497+
{
2498+
public:
2499+
explicit code_function_bodyt(
2500+
const std::vector<irep_idt> &parameter_identifiers,
2501+
code_blockt _block)
2502+
: codet(ID_function_body, {std::move(_block)})
2503+
{
2504+
set_parameter_identifiers(parameter_identifiers);
2505+
}
2506+
2507+
code_blockt &block()
2508+
{
2509+
return to_code_block(to_code(op0()));
2510+
}
2511+
2512+
const code_blockt &block() const
2513+
{
2514+
return to_code_block(to_code(op0()));
2515+
}
2516+
2517+
std::vector<irep_idt> get_parameter_identifiers() const;
2518+
void set_parameter_identifiers(const std::vector<irep_idt> &);
2519+
2520+
protected:
2521+
using codet::op0;
2522+
using codet::op1;
2523+
using codet::op2;
2524+
using codet::op3;
2525+
};
2526+
2527+
inline const code_function_bodyt &to_code_function_body(const codet &code)
2528+
{
2529+
PRECONDITION(code.get_statement() == ID_function_body);
2530+
DATA_INVARIANT(
2531+
code.operands().size() == 1, "code_function_body must have one operand");
2532+
return static_cast<const code_function_bodyt &>(code);
2533+
}
2534+
2535+
inline code_function_bodyt &to_code_function_body(codet &code)
2536+
{
2537+
PRECONDITION(code.get_statement() == ID_function_body);
2538+
DATA_INVARIANT(
2539+
code.operands().size() == 1, "code_function_body must have one operand");
2540+
return static_cast<code_function_bodyt &>(code);
2541+
}
2542+
24932543
#endif // CPROVER_UTIL_STD_CODE_H

0 commit comments

Comments
 (0)