Skip to content

Commit 99c21ed

Browse files
author
thk123
committed
Extended find pointer assignment to take a regex
1 parent 5610aca commit 99c21ed

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

unit/testing-utils/require_goto_statements.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,19 @@ require_goto_statements::pointer_assignment_locationt
151151
require_goto_statements::find_pointer_assignments(
152152
const irep_idt &pointer_name,
153153
const std::vector<codet> &instructions)
154+
{
155+
INFO("Looking for symbol: " << pointer_name);
156+
std::regex special_chars{R"([-[\]{}()*+?.,\^$|#\s])"};
157+
std::string sanitized =
158+
std::regex_replace(id2string(pointer_name), special_chars, R"(\$&)");
159+
return find_pointer_assignments(
160+
std::regex("^" + sanitized + "$"), instructions);
161+
}
162+
163+
require_goto_statements::pointer_assignment_locationt
164+
require_goto_statements::find_pointer_assignments(
165+
const std::regex &pointer_name_match,
166+
const std::vector<codet> &instructions)
154167
{
155168
pointer_assignment_locationt locations;
156169
bool found_assignment = false;
@@ -164,7 +177,9 @@ require_goto_statements::find_pointer_assignments(
164177
{
165178
const symbol_exprt &symbol_expr = to_symbol_expr(code_assign.lhs());
166179
all_symbols.push_back(symbol_expr.get_identifier());
167-
if(symbol_expr.get_identifier() == pointer_name)
180+
if(
181+
std::regex_search(
182+
id2string(symbol_expr.get_identifier()), pointer_name_match))
168183
{
169184
if(
170185
code_assign.rhs() ==
@@ -181,7 +196,7 @@ require_goto_statements::find_pointer_assignments(
181196
}
182197
}
183198
}
184-
INFO("Looking for symbol: " << pointer_name);
199+
185200
std::ostringstream found_symbols;
186201
for(const auto entry : all_symbols)
187202
{

unit/testing-utils/require_goto_statements.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#include <util/std_types.h>
1717
#include <goto-programs/goto_program.h>
1818

19+
#include <regex>
20+
1921
#ifndef CPROVER_TESTING_UTILS_REQUIRE_GOTO_STATEMENTS_H
2022
#define CPROVER_TESTING_UTILS_REQUIRE_GOTO_STATEMENTS_H
2123

@@ -81,6 +83,10 @@ pointer_assignment_locationt find_pointer_assignments(
8183
const irep_idt &pointer_name,
8284
const std::vector<codet> &instructions);
8385

86+
pointer_assignment_locationt find_pointer_assignments(
87+
const std::regex &pointer_name_match,
88+
const std::vector<codet> &instructions);
89+
8490
const code_declt &require_declaration_of_name(
8591
const irep_idt &variable_name,
8692
const std::vector<codet> &entry_point_instructions);

0 commit comments

Comments
 (0)