@@ -13,7 +13,6 @@ Author: Daniel Kroening, kroening@kroening.com
1313
1414#include < util/suffix.h>
1515#include < util/prefix.h>
16- #include < util/config.h>
1716
1817#include " java_bytecode_parser.h"
1918
@@ -69,6 +68,19 @@ java_class_loadert::parse_tree_with_overlayst &java_class_loadert::operator()(
6968 return class_map.at (class_name);
7069}
7170
71+ void java_class_loadert::add_classpath_entry (const std::string &path)
72+ {
73+ if (has_suffix (path, " .jar" ))
74+ {
75+ classpath_entries.push_back (classpath_entryt (classpath_entryt::JAR, path));
76+ }
77+ else
78+ {
79+ classpath_entries.push_back (
80+ classpath_entryt (classpath_entryt::DIRECTORY, path));
81+ }
82+ }
83+
7284optionalt<java_bytecode_parse_treet> java_class_loadert::get_class_from_jar (
7385 const irep_idt &class_name,
7486 const std::string &jar_file,
@@ -124,55 +136,44 @@ java_class_loadert::get_parse_tree(
124136 return parse_trees;
125137 }
126138
127- // First add all given JAR files
128- for (const auto &jar_file : jar_files )
139+ // Rummage through the class path
140+ for (const auto &cp_entry : classpath_entries )
129141 {
130- jar_index_optcreft index = read_jar_file (jar_file);
131- if (!index)
132- continue ;
133- optionalt<java_bytecode_parse_treet> parse_tree =
134- get_class_from_jar (class_name, jar_file, *index);
135- if (parse_tree)
136- parse_trees.emplace_back (std::move (*parse_tree));
137- }
138-
139- // Then add everything on the class path
140- for (const auto &cp_entry : config.java .classpath )
141- {
142- if (has_suffix (cp_entry, " .jar" ))
143- {
144- jar_index_optcreft index = read_jar_file (cp_entry);
145- if (!index)
146- continue ;
147- optionalt<java_bytecode_parse_treet> parse_tree =
148- get_class_from_jar (class_name, cp_entry, *index);
149- if (parse_tree)
150- parse_trees.emplace_back (std::move (*parse_tree));
151- }
152- else
142+ switch (cp_entry.kind )
153143 {
154- // Look in the given directory
155- const std::string class_file = class_name_to_file (class_name);
156- const std::string full_path =
157- #ifdef _WIN32
158- cp_entry + ' \\ ' + class_file;
159- #else
160- cp_entry + ' /' + class_file;
161- #endif
162-
163- if (!class_loader_limit.load_class_file (class_file))
164- continue ;
165-
166- if (std::ifstream (full_path))
144+ case classpath_entryt::JAR:
167145 {
168- debug ()
169- << " Getting class ` " << class_name << " ' from file " << full_path
170- << eom ;
146+ jar_index_optcreft index = read_jar_file (cp_entry. path );
147+ if (!index)
148+ continue ;
171149 optionalt<java_bytecode_parse_treet> parse_tree =
172- java_bytecode_parse (full_path, get_message_handler () );
150+ get_class_from_jar (class_name, cp_entry. path , *index );
173151 if (parse_tree)
174152 parse_trees.emplace_back (std::move (*parse_tree));
175153 }
154+ break ;
155+
156+ case classpath_entryt::DIRECTORY:
157+ {
158+ // Look in the given directory
159+ const std::string class_file = class_name_to_file (class_name);
160+ const std::string full_path =
161+ #ifdef _WIN32
162+ cp_entry.path + ' \\ ' + class_file;
163+ #else
164+ cp_entry.path + ' /' + class_file;
165+ #endif
166+
167+ if (std::ifstream (full_path))
168+ {
169+ debug () << " Getting class `" << class_name << " ' from file "
170+ << full_path << eom;
171+ optionalt<java_bytecode_parse_treet> parse_tree =
172+ java_bytecode_parse (full_path, get_message_handler ());
173+ if (parse_tree)
174+ parse_trees.emplace_back (std::move (*parse_tree));
175+ }
176+ }
176177 }
177178 }
178179
@@ -234,12 +235,13 @@ void java_class_loadert::load_entire_jar(
234235 if (!jar_index)
235236 return ;
236237
237- jar_files.push_front (jar_path);
238+ classpath_entries.push_front (
239+ classpath_entryt (classpath_entryt::JAR, jar_path));
238240
239241 for (const auto &e : jar_index->get ())
240242 operator ()(e.first );
241243
242- jar_files .pop_front ();
244+ classpath_entries .pop_front ();
243245}
244246
245247java_class_loadert::jar_index_optcreft java_class_loadert::read_jar_file (
0 commit comments