16
16
17
17
#include " java_bytecode_parser.h"
18
18
19
- java_class_loadert::parse_tree_with_overlayst &java_class_loadert::operator ()(
20
- const irep_idt &class_name)
19
+ java_class_loadert::parse_tree_with_overlayst &java_class_loadert::
20
+ operator ()( const irep_idt &class_name, message_handlert &message_handler )
21
21
{
22
- debug () << " Classpath:" ;
22
+ messaget log (message_handler);
23
+
24
+ log.debug () << " Classpath:" ;
23
25
for (const auto &entry : classpath_entries)
24
26
{
25
- debug () << " \n " << entry.path ;
27
+ log. debug () << " \n " << entry.path ;
26
28
}
27
- debug () << messaget::eom;
29
+ log. debug () << messaget::eom;
28
30
29
31
std::stack<irep_idt> queue;
30
32
// Always require java.lang.Object, as it is the base of
@@ -44,7 +46,7 @@ java_class_loadert::parse_tree_with_overlayst &java_class_loadert::operator()(
44
46
queue.push (id);
45
47
46
48
java_class_loader_limitt class_loader_limit (
47
- get_message_handler () , java_cp_include_files);
49
+ message_handler , java_cp_include_files);
48
50
49
51
while (!queue.empty ())
50
52
{
@@ -54,10 +56,10 @@ java_class_loadert::parse_tree_with_overlayst &java_class_loadert::operator()(
54
56
if (class_map.count (c) != 0 )
55
57
continue ;
56
58
57
- debug () << " Reading class " << c << eom;
59
+ log. debug () << " Reading class " << c << messaget:: eom;
58
60
59
61
parse_tree_with_overlayst &parse_trees =
60
- get_parse_tree (class_loader_limit, c);
62
+ get_parse_tree (class_loader_limit, c, message_handler );
61
63
62
64
// Add any dependencies to queue
63
65
for (const java_bytecode_parse_treet &parse_tree : parse_trees)
@@ -103,11 +105,13 @@ static bool is_overlay_class(const java_bytecode_parse_treet::classt &c)
103
105
.has_value ();
104
106
}
105
107
106
- bool java_class_loadert::can_load_class (const irep_idt &class_name)
108
+ bool java_class_loadert::can_load_class (
109
+ const irep_idt &class_name,
110
+ message_handlert &message_handler)
107
111
{
108
112
for (const auto &cp_entry : classpath_entries)
109
113
{
110
- auto parse_tree = load_class (class_name, cp_entry);
114
+ auto parse_tree = load_class (class_name, cp_entry, message_handler );
111
115
if (parse_tree.has_value ())
112
116
return true ;
113
117
}
@@ -121,6 +125,7 @@ bool java_class_loadert::can_load_class(const irep_idt &class_name)
121
125
// / to find the .class file.
122
126
// / \param class_loader_limit: Filter to decide whether to load classes
123
127
// / \param class_name: Name of class to load
128
+ // / \param message_handler: message handler
124
129
// / \return The list of valid implementations, including overlays
125
130
// / \remarks
126
131
// / Allows multiple definitions of the same class to appear on the
@@ -129,23 +134,27 @@ bool java_class_loadert::can_load_class(const irep_idt &class_name)
129
134
java_class_loadert::parse_tree_with_overlayst &
130
135
java_class_loadert::get_parse_tree (
131
136
java_class_loader_limitt &class_loader_limit,
132
- const irep_idt &class_name)
137
+ const irep_idt &class_name,
138
+ message_handlert &message_handler)
133
139
{
134
140
parse_tree_with_overlayst &parse_trees = class_map[class_name];
135
141
PRECONDITION (parse_trees.empty ());
136
142
143
+ messaget log (message_handler);
144
+
137
145
// do we refuse to load?
138
146
if (!class_loader_limit.load_class_file (class_name_to_jar_file (class_name)))
139
147
{
140
- debug () << " not loading " << class_name << " because of limit" << eom;
148
+ log.debug () << " not loading " << class_name << " because of limit"
149
+ << messaget::eom;
141
150
parse_trees.emplace_back (class_name);
142
151
return parse_trees;
143
152
}
144
153
145
154
// Rummage through the class path
146
155
for (const auto &cp_entry : classpath_entries)
147
156
{
148
- auto parse_tree = load_class (class_name, cp_entry);
157
+ auto parse_tree = load_class (class_name, cp_entry, message_handler );
149
158
if (parse_tree.has_value ())
150
159
parse_trees.emplace_back (std::move (*parse_tree));
151
160
}
@@ -164,10 +173,10 @@ java_class_loadert::get_parse_tree(
164
173
++parse_tree_it;
165
174
break ;
166
175
}
167
- debug () << " Skipping class " << class_name
168
- << " marked with OverlayClassImplementation but found before"
169
- " original definition"
170
- << eom;
176
+ log. debug () << " Skipping class " << class_name
177
+ << " marked with OverlayClassImplementation but found before"
178
+ " original definition"
179
+ << messaget:: eom;
171
180
}
172
181
auto unloaded_or_overlay_out_of_order_it = parse_tree_it;
173
182
++parse_tree_it;
@@ -179,8 +188,9 @@ java_class_loadert::get_parse_tree(
179
188
// Remove non-initial classes that aren't overlays
180
189
if (!is_overlay_class (parse_tree_it->parsed_class ))
181
190
{
182
- debug () << " Skipping duplicate definition of class " << class_name
183
- << " not marked with OverlayClassImplementation" << eom;
191
+ log.debug () << " Skipping duplicate definition of class " << class_name
192
+ << " not marked with OverlayClassImplementation"
193
+ << messaget::eom;
184
194
auto duplicate_non_overlay_it = parse_tree_it;
185
195
++parse_tree_it;
186
196
parse_trees.erase (duplicate_non_overlay_it);
@@ -192,45 +202,50 @@ java_class_loadert::get_parse_tree(
192
202
return parse_trees;
193
203
194
204
// Not found or failed to load
195
- debug () << " failed to load class " << class_name << eom;
205
+ log. debug () << " failed to load class " << class_name << messaget:: eom;
196
206
parse_trees.emplace_back (class_name);
197
207
return parse_trees;
198
208
}
199
209
200
210
// / Load all class files from a .jar file
201
211
// / \param jar_path: the path for the .jar to load
202
212
std::vector<irep_idt> java_class_loadert::load_entire_jar (
203
- const std::string &jar_path)
213
+ const std::string &jar_path,
214
+ message_handlert &message_handler)
204
215
{
205
- auto classes = read_jar_file (jar_path);
216
+ auto classes = read_jar_file (jar_path, message_handler );
206
217
if (!classes.has_value ())
207
218
return {};
208
219
209
220
classpath_entries.push_front (
210
221
classpath_entryt (classpath_entryt::JAR, jar_path));
211
222
212
223
for (const auto &c : *classes)
213
- operator ()(c);
224
+ operator ()(c, message_handler );
214
225
215
226
classpath_entries.pop_front ();
216
227
217
228
return *classes;
218
229
}
219
230
220
- optionalt<std::vector<irep_idt>>
221
- java_class_loadert::read_jar_file (const std::string &jar_path)
231
+ optionalt<std::vector<irep_idt>> java_class_loadert::read_jar_file (
232
+ const std::string &jar_path,
233
+ message_handlert &message_handler)
222
234
{
235
+ messaget log (message_handler);
236
+
223
237
std::vector<std::string> filenames;
224
238
try
225
239
{
226
240
filenames = jar_pool (jar_path).filenames ();
227
241
}
228
242
catch (const std::runtime_error &)
229
243
{
230
- error () << " failed to open JAR file '" << jar_path << " '" << eom;
244
+ log.error () << " failed to open JAR file '" << jar_path << " '"
245
+ << messaget::eom;
231
246
return {};
232
247
}
233
- debug () << " Adding JAR file '" << jar_path << " '" << eom;
248
+ log. debug () << " Adding JAR file '" << jar_path << " '" << messaget:: eom;
234
249
235
250
// Create a new entry in the map and initialize using the list of file names
236
251
// that are in jar_filet
@@ -239,8 +254,8 @@ java_class_loadert::read_jar_file(const std::string &jar_path)
239
254
{
240
255
if (has_suffix (file_name, " .class" ))
241
256
{
242
- debug () << " Found class file " << file_name << " in JAR '" << jar_path
243
- << " '" << eom;
257
+ log. debug () << " Found class file " << file_name << " in JAR '" << jar_path
258
+ << " '" << messaget:: eom;
244
259
irep_idt class_name=file_to_class_name (file_name);
245
260
classes.push_back (class_name);
246
261
}
0 commit comments