cprover
java_class_loader.h
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module:
4 
5 Author: Daniel Kroening, kroening@kroening.com
6 
7 \*******************************************************************/
8 
9 
10 #ifndef CPROVER_JAVA_BYTECODE_JAVA_CLASS_LOADER_H
11 #define CPROVER_JAVA_BYTECODE_JAVA_CLASS_LOADER_H
12 
13 #include <map>
14 #include <regex>
15 #include <set>
16 
17 #include <util/message.h>
19 
22 #include "jar_file.h"
23 
25 {
26 public:
29  typedef std::map<irep_idt, std::string> jar_indext;
30 
31  typedef std::list<java_bytecode_parse_treet> parse_tree_with_overlayst;
32  typedef std::map<irep_idt, parse_tree_with_overlayst>
34 
36  typedef std::function<std::vector<irep_idt>(const irep_idt &)>
38 
40  {
41  }
42 
43  parse_tree_with_overlayst &operator()(const irep_idt &class_name);
44 
53  java_class_loader_limitt &class_loader_limit,
54  const irep_idt &class_name);
55 
57  {
58  this->java_cp_include_files = java_cp_include_files;
59  }
65  {
66  get_extra_class_refs = func;
67  }
71  void add_load_classes(const std::vector<irep_idt> &classes)
72  {
73  for(const auto &id : classes)
74  java_load_classes.push_back(id);
75  }
76  void add_jar_file(const std::string &f)
77  {
78  jar_files.push_back(f);
79  }
80 
81  static std::string file_to_class_name(const std::string &);
82  static std::string class_name_to_file(const irep_idt &);
83 
84  void load_entire_jar(java_class_loader_limitt &, const std::string &jar_path);
85 
86  const jar_indext &get_jar_index(const std::string &jar_path)
87  {
88  return jars_by_path.at(jar_path);
89  }
93  {
95  }
97  const irep_idt &class_name)
98  {
99  return class_map.at(class_name).front();
100  }
101 
106  java_class_loader_limitt &limit, const std::string &filename);
107 
117  const std::string &buffer_name,
118  const void *pmem,
119  size_t size);
120 
121 private:
128 
132  std::list<std::string> jar_files;
133 
135  std::vector<irep_idt> java_load_classes;
137 
139  std::map<std::string, jar_indext> jars_by_path;
140 
142  std::map<std::string, jar_filet> m_archives;
145 
149  java_class_loader_limitt &class_loader_limit,
150  const std::string &jar_path);
152  const irep_idt &class_name,
153  const std::string &jar_file,
154  const jar_indext &jar_index,
155  java_class_loader_limitt &class_loader_limit);
156 };
157 
158 #endif // CPROVER_JAVA_BYTECODE_JAVA_CLASS_LOADER_H
std::map< std::string, jar_indext > jars_by_path
The jar_indext for each jar file we&#39;ve read.
jar_index_optcreft read_jar_file(java_class_loader_limitt &class_loader_limit, const std::string &jar_path)
std::list< std::string > jar_files
List of filesystem paths to .jar files that will be used, in the given order, to find and load a clas...
const jar_indext & get_jar_index(const std::string &jar_path)
std::vector< irep_idt > java_load_classes
Classes to be explicitly loaded.
std::function< std::vector< irep_idt >const irep_idt &)> get_extra_class_refs_functiont
A function that yields a list of extra dependencies based on a class name.
parse_tree_with_overlayst & get_parse_tree(java_class_loader_limitt &class_loader_limit, const irep_idt &class_name)
Given a class_name (e.g.
std::map< irep_idt, parse_tree_with_overlayst > parse_tree_with_overridest_mapt
jar_filet & jar_pool(java_class_loader_limitt &limit, const std::string &filename)
Load jar archive or retrieve from cache if already loaded.
std::map< irep_idt, std::string > jar_indext
A map associating logical class names with the name of the .class file implementing it for all classe...
std::list< java_bytecode_parse_treet > parse_tree_with_overlayst
void load_entire_jar(java_class_loader_limitt &, const std::string &jar_path)
static std::string file_to_class_name(const std::string &)
fixed_keys_map_wrappert< parse_tree_with_overridest_mapt > get_class_with_overlays_map()
Map from class names to the bytecode parse trees.
void add_jar_file(const std::string &f)
void set_java_cp_include_files(const std::string &java_cp_include_files)
nonstd::optional< T > optionalt
Definition: optional.h:35
dstringt has one field, an unsigned integer no which is an index into a static table of strings...
Definition: dstring.h:33
Class representing a .jar archive.
Definition: jar_file.h:22
void add_load_classes(const std::vector< irep_idt > &classes)
Adds the list of classes to the load queue, forcing them to be loaded even without explicit reference...
A wrapper for maps that gives read-write access to elements but without allowing addition or removal ...
void set_extra_class_refs_function(get_extra_class_refs_functiont func)
Sets a function that provides extra dependencies for a particular class.
optionalt< std::reference_wrapper< const jar_indext > > jar_index_optcreft
std::map< std::string, jar_filet > m_archives
Jar files that have been loaded.
get_extra_class_refs_functiont get_extra_class_refs
parse_tree_with_overlayst & operator()(const irep_idt &class_name)
const java_bytecode_parse_treet & get_original_class(const irep_idt &class_name)
optionalt< java_bytecode_parse_treet > get_class_from_jar(const irep_idt &class_name, const std::string &jar_file, const jar_indext &jar_index, java_class_loader_limitt &class_loader_limit)
std::string java_cp_include_files
Either a regular expression matching files that will be allowed to be loaded or a string of the form ...
limit class path loading
parse_tree_with_overridest_mapt class_map
Map from class names to the bytecode parse trees.
static std::string class_name_to_file(const irep_idt &)