Skip to content

Commit 8999cf6

Browse files
author
thk123
committed
Added utiltity for getting this member components
Add documentation to find pointer assignments for a component
1 parent 3e0e12e commit 8999cf6

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

unit/testing-utils/require_goto_statements.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <util/expr_iterator.h>
1414
#include <goto-programs/goto_functions.h>
1515
#include <java_bytecode/java_types.h>
16+
#include <util/suffix.h>
1617

1718
/// Expand value of a function to include all child codets
1819
/// \param function_value: The value of the function (e.g. got by looking up
@@ -141,6 +142,53 @@ require_goto_statements::find_struct_component_assignments(
141142
return locations;
142143
}
143144

145+
/// Find assignment statements that set this->{component_name}
146+
/// \param statements The statements to look through
147+
/// \param component_name The name of the component whose assignments we are
148+
/// looking for.
149+
/// \return A collection of all non-null assignments to this component
150+
/// and, if present, a null assignment.
151+
require_goto_statements::pointer_assignment_locationt
152+
require_goto_statements::find_this_component_assignment(
153+
const std::vector<codet> &statements,
154+
const irep_idt &component_name)
155+
{
156+
pointer_assignment_locationt locations;
157+
158+
for(const auto &assignment : statements)
159+
{
160+
if(assignment.get_statement() == ID_assign)
161+
{
162+
const code_assignt &code_assign = to_code_assign(assignment);
163+
164+
if(code_assign.lhs().id() == ID_member)
165+
{
166+
const member_exprt &member_expr = to_member_expr(code_assign.lhs());
167+
if(
168+
member_expr.get_component_name() == component_name &&
169+
member_expr.op().id() == ID_dereference &&
170+
member_expr.op().op0().id() == ID_symbol &&
171+
has_suffix(
172+
id2string(to_symbol_expr(member_expr.op().op0()).get_identifier()),
173+
"this"))
174+
{
175+
if(
176+
code_assign.rhs() ==
177+
null_pointer_exprt(to_pointer_type(code_assign.lhs().type())))
178+
{
179+
locations.null_assignment = code_assign;
180+
}
181+
else
182+
{
183+
locations.non_null_assignments.push_back(code_assign);
184+
}
185+
}
186+
}
187+
}
188+
}
189+
return locations;
190+
}
191+
144192
/// For a given variable name, gets the assignments to it in the provided
145193
/// instructions.
146194
/// \param pointer_name: The name of the variable

unit/testing-utils/require_goto_statements.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ pointer_assignment_locationt find_struct_component_assignments(
7474
const optionalt<irep_idt> &superclass_name,
7575
const irep_idt &component_name);
7676

77+
pointer_assignment_locationt find_this_component_assignment(
78+
const std::vector<codet> &statements,
79+
const irep_idt &component_name);
80+
7781
std::vector<codet> get_all_statements(const exprt &function_value);
7882

7983
const std::vector<codet>

0 commit comments

Comments
 (0)