@@ -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,51 @@ 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};
30+ return std::regex{modified_pattern};
3231}
3332
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;
53- }
5433
5534// / Identify if a parameter includes a part that will match a descriptor. That
5635// / is, does it have a colon separtor.
5736// / \param pattern: The user provided pattern
5837// / \return True if no descriptor is found (that is, the only : relates to the
5938// / java:: prefix.
60- bool load_method_by_regext::does_pattern_miss_descriptor (
61- const std::string &pattern)
39+ bool does_pattern_miss_descriptor (const std::string &pattern)
6240{
6341 const size_t descriptor_index = pattern.rfind (' :' );
6442 if (descriptor_index == std::string::npos)
6543 return true ;
6644
6745 static const std::string java_prefix = " java::" ;
6846 return descriptor_index == java_prefix.length () - 1 &&
69- has_prefix (pattern, " java::" );
47+ has_prefix (pattern, java_prefix);
48+ }
49+
50+ // / Create a lambda that returns the symbols that the given pattern should be
51+ // / loaded.If the pattern doesn't include a colon for matching the descriptor,
52+ // / append a `:\(.*\).*` to the regex. Note this will mean all overloaded
53+ // / methods will be marked as extra entry points for CI lazy loading.
54+ // / If the pattern doesn't include the java:: prefix, prefix that
55+ // / \param pattern: The user provided pattern
56+ // / \return The lambda to execute.
57+ std::function<std::vector<irep_idt>(const symbol_tablet &symbol_table)>
58+ build_load_method_by_regex (const std::string &pattern)
59+ {
60+ std::regex regex = build_regex_from_pattern (pattern);
61+
62+ return [=](const symbol_tablet &symbol_table) {
63+ std::vector<irep_idt> matched_methods;
64+ for (const auto &symbol : symbol_table.symbols )
65+ {
66+ if (symbol.second .is_function ())
67+ {
68+ const std::string symbol_name = id2string (symbol.first );
69+ if (std::regex_match (symbol_name, regex))
70+ {
71+ matched_methods.push_back (symbol_name);
72+ }
73+ }
74+ }
75+ return matched_methods;
76+ };
7077}
0 commit comments