@@ -13,13 +13,12 @@ Author: Diffblue Ltd.
13
13
14
14
#include < util/symbol_table.h>
15
15
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
21
19
// / \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)
23
22
{
24
23
std::string modified_pattern = pattern;
25
24
if (does_pattern_miss_descriptor (pattern))
@@ -28,43 +27,50 @@ load_method_by_regext::load_method_by_regext(const std::string &pattern)
28
27
if (!has_prefix (pattern, " java::" ))
29
28
modified_pattern = " java::" + modified_pattern;
30
29
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};
53
31
}
54
32
55
33
// / Identify if a parameter includes a part that will match a descriptor. That
56
34
// / is, does it have a colon separtor.
57
35
// / \param pattern: The user provided pattern
58
36
// / \return True if no descriptor is found (that is, the only : relates to the
59
37
// / 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)
62
39
{
63
40
const size_t descriptor_index = pattern.rfind (' :' );
64
41
if (descriptor_index == std::string::npos)
65
42
return true ;
66
43
67
44
static const std::string java_prefix = " java::" ;
68
45
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
+ };
70
76
}
0 commit comments