@@ -13,13 +13,12 @@ Author: Diffblue Ltd.
1313
1414#include < util/symbol_table.h>
1515
16- // / Create a load_method_by_regext matching the pattern. If the pattern doesn't
17- // / include a colon for matching the descriptor, append a `:\(.*\).*` to the
18- // / regex. Note this will mean all overloaded methods will be marked as extra
19- // / entry points for CI lazy loading.
20- // / If the pattern doesn't include the java:: prefix, prefix that
16+ // / For a given user provided pattern, return a regex, having dealt with the
17+ // / cases where the user has not prefixed with java:: or suffixed with the
18+ // / descriptor
2119// / \param pattern: The user provided pattern
22- load_method_by_regext::load_method_by_regext (const std::string &pattern)
20+ // / \return The regex to match with
21+ static std::regex build_regex_from_pattern (const std::string &pattern)
2322{
2423 std::string modified_pattern = pattern;
2524 if (does_pattern_miss_descriptor (pattern))
@@ -28,43 +27,50 @@ load_method_by_regext::load_method_by_regext(const std::string &pattern)
2827 if (!has_prefix (pattern, " java::" ))
2928 modified_pattern = " java::" + modified_pattern;
3029
31- regex = std::regex{modified_pattern};
32- }
33-
34- // / Get the methods that match the regex
35- // / \param symbol_table: The symbol table to look through
36- // / \return: The method identifiers that should be loaded
37- std::vector<irep_idt>
38- load_method_by_regext::extra_methods (const symbol_tablet &symbol_table) const
39- {
40- std::vector<irep_idt> matched_methods;
41- for (const auto &symbol : symbol_table.symbols )
42- {
43- if (symbol.second .is_function ())
44- {
45- const std::string symbol_name = id2string (symbol.first );
46- if (std::regex_match (symbol_name, regex))
47- {
48- matched_methods.push_back (symbol_name);
49- }
50- }
51- }
52- return matched_methods;
30+ return std::regex{modified_pattern};
5331}
5432
5533// / Identify if a parameter includes a part that will match a descriptor. That
5634// / is, does it have a colon separtor.
5735// / \param pattern: The user provided pattern
5836// / \return True if no descriptor is found (that is, the only : relates to the
5937// / java:: prefix.
60- bool load_method_by_regext::does_pattern_miss_descriptor (
61- const std::string &pattern)
38+ bool does_pattern_miss_descriptor (const std::string &pattern)
6239{
6340 const size_t descriptor_index = pattern.rfind (' :' );
6441 if (descriptor_index == std::string::npos)
6542 return true ;
6643
6744 static const std::string java_prefix = " java::" ;
6845 return descriptor_index == java_prefix.length () - 1 &&
69- has_prefix (pattern, " java::" );
46+ has_prefix (pattern, java_prefix);
47+ }
48+
49+ // / Create a lambda that returns the symbols that the given pattern should be
50+ // / loaded.If the pattern doesn't include a colon for matching the descriptor,
51+ // / append a `:\(.*\).*` to the regex. Note this will mean all overloaded
52+ // / methods will be marked as extra entry points for CI lazy loading.
53+ // / If the pattern doesn't include the java:: prefix, prefix that
54+ // / \param pattern: The user provided pattern
55+ // / \return The lambda to execute.
56+ std::function<std::vector<irep_idt>(const symbol_tablet &symbol_table)>
57+ build_load_method_by_regex (const std::string &pattern)
58+ {
59+ std::regex regex = build_regex_from_pattern (pattern);
60+
61+ return [=](const symbol_tablet &symbol_table) {
62+ std::vector<irep_idt> matched_methods;
63+ for (const auto &symbol : symbol_table.symbols )
64+ {
65+ if (symbol.second .is_function ())
66+ {
67+ const std::string symbol_name = id2string (symbol.first );
68+ if (std::regex_match (symbol_name, regex))
69+ {
70+ matched_methods.push_back (symbol_name);
71+ }
72+ }
73+ }
74+ return matched_methods;
75+ };
7076}
0 commit comments