cprover
load_method_by_regex.cpp
Go to the documentation of this file.
1 
2 /*******************************************************************\
3 
4 Module: Java Bytecode
5 
6 Author: Diffblue Ltd.
7 
8 \*******************************************************************/
9 
10 #include "load_method_by_regex.h"
11 
12 #include <regex>
13 
14 #include <util/symbol_table.h>
15 
21 static std::regex build_regex_from_pattern(const std::string &pattern)
22 {
23  std::string modified_pattern = pattern;
24  if(does_pattern_miss_descriptor(pattern))
25  modified_pattern += R"(:\(.*\).*)";
26 
27  if(!has_prefix(pattern, "java::"))
28  modified_pattern = "java::" + modified_pattern;
29 
30  return std::regex{modified_pattern};
31 }
32 
38 bool does_pattern_miss_descriptor(const std::string &pattern)
39 {
40  const size_t descriptor_index = pattern.rfind(':');
41  if(descriptor_index == std::string::npos)
42  return true;
43 
44  const std::string java_prefix = "java::";
45  return descriptor_index == java_prefix.length() - 1 &&
46  has_prefix(pattern, java_prefix);
47 }
48 
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(
66  symbol.second.is_function() &&
67  std::regex_match(id2string(symbol.first), regex))
68  {
69  matched_methods.push_back(symbol.first);
70  }
71  }
72  return matched_methods;
73  };
74 }
symbol_tablet
The symbol table.
Definition: symbol_table.h:19
load_method_by_regex.h
does_pattern_miss_descriptor
bool does_pattern_miss_descriptor(const std::string &pattern)
Identify if a parameter includes a part that will match a descriptor.
Definition: load_method_by_regex.cpp:38
id2string
const std::string & id2string(const irep_idt &d)
Definition: irep.h:44
build_load_method_by_regex
std::function< std::vector< irep_idt >const symbol_tablet &symbol_table)> build_load_method_by_regex(const std::string &pattern)
Create a lambda that returns the symbols that the given pattern should be loaded.If the pattern doesn...
Definition: load_method_by_regex.cpp:57
build_regex_from_pattern
static std::regex build_regex_from_pattern(const std::string &pattern)
For a given user provided pattern, return a regex, having dealt with the cases where the user has not...
Definition: load_method_by_regex.cpp:21
has_prefix
bool has_prefix(const std::string &s, const std::string &prefix)
Definition: converter.cpp:13
symbol_table.h
Author: Diffblue Ltd.