@@ -13,7 +13,6 @@ Author: Daniel Kroening, kroening@kroening.com
13
13
14
14
#include < util/suffix.h>
15
15
#include < util/prefix.h>
16
- #include < util/config.h>
17
16
18
17
#include " java_bytecode_parser.h"
19
18
@@ -69,6 +68,19 @@ java_class_loadert::parse_tree_with_overlayst &java_class_loadert::operator()(
69
68
return class_map.at (class_name);
70
69
}
71
70
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
+
72
84
optionalt<java_bytecode_parse_treet> java_class_loadert::get_class_from_jar (
73
85
const irep_idt &class_name,
74
86
const std::string &jar_file,
@@ -124,55 +136,44 @@ java_class_loadert::get_parse_tree(
124
136
return parse_trees;
125
137
}
126
138
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 )
129
141
{
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 )
153
143
{
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:
167
145
{
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 ;
171
149
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 );
173
151
if (parse_tree)
174
152
parse_trees.emplace_back (std::move (*parse_tree));
175
153
}
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
+ }
176
177
}
177
178
}
178
179
@@ -234,12 +235,13 @@ void java_class_loadert::load_entire_jar(
234
235
if (!jar_index)
235
236
return ;
236
237
237
- jar_files.push_front (jar_path);
238
+ classpath_entries.push_front (
239
+ classpath_entryt (classpath_entryt::JAR, jar_path));
238
240
239
241
for (const auto &e : jar_index->get ())
240
242
operator ()(e.first );
241
243
242
- jar_files .pop_front ();
244
+ classpath_entries .pop_front ();
243
245
}
244
246
245
247
java_class_loadert::jar_index_optcreft java_class_loadert::read_jar_file (
0 commit comments