@@ -210,6 +210,125 @@ class java_bytecode_parsert:public parsert
210
210
#define VTYPE_INFO_OBJECT 7
211
211
#define VTYPE_INFO_UNINIT 8
212
212
213
+
214
+ class structured_pool_entryt
215
+ {
216
+ public:
217
+ explicit structured_pool_entryt (java_bytecode_parsert::pool_entryt entry)
218
+ : tag(entry.tag)
219
+ {
220
+ }
221
+
222
+ u1 get_tag () const { return tag; }
223
+
224
+ typedef std::function<java_bytecode_parsert::pool_entryt &(u2)> pool_entry_lookupt;
225
+ typedef java_bytecode_parsert::pool_entryt pool_entryt;
226
+
227
+ protected:
228
+ static std::string read_utf8_constant (const pool_entryt &entry)
229
+ {
230
+ INVARIANT (
231
+ entry.tag == CONSTANT_Utf8, " Name entry must be a constant UTF-8" );
232
+ return id2string (entry.s );
233
+ }
234
+
235
+ private:
236
+ u1 tag;
237
+ };
238
+
239
+ // / Corresponds to the CONSTANT_Class_info Structure
240
+ // / Described in Java 8 specification 4.4.1
241
+ class class_infot : public structured_pool_entryt
242
+ {
243
+ public:
244
+ explicit class_infot (const pool_entryt &entry): structured_pool_entryt(entry)
245
+ {
246
+ PRECONDITION (entry.tag == CONSTANT_Class);
247
+ name_index=entry.ref1 ;
248
+ }
249
+
250
+ std::string get_name (pool_entry_lookupt pool_entry) const
251
+ {
252
+ const pool_entryt &name_entry = pool_entry (name_index);
253
+ return read_utf8_constant (name_entry);
254
+ }
255
+
256
+ private:
257
+ u2 name_index;
258
+ };
259
+
260
+ // / Corresponds to the CONSTANT_NameAndType_info Structure
261
+ // / Described in Java 8 specification 4.4.6
262
+ class name_and_type_infot : public structured_pool_entryt
263
+ {
264
+ public:
265
+ explicit name_and_type_infot (java_bytecode_parsert::pool_entryt entry)
266
+ : structured_pool_entryt(entry)
267
+ {
268
+ PRECONDITION (entry.tag == CONSTANT_NameAndType);
269
+ name_index = entry.ref1 ;
270
+ descriptor_index = entry.ref2 ;
271
+ }
272
+
273
+ std::string get_name (pool_entry_lookupt pool_entry) const
274
+ {
275
+ const pool_entryt &name_entry = pool_entry (name_index);
276
+ return read_utf8_constant (name_entry);
277
+ }
278
+
279
+ std::string get_descriptor (pool_entry_lookupt pool_entry) const
280
+ {
281
+ const pool_entryt &descriptor_entry = pool_entry (descriptor_index);
282
+ return read_utf8_constant (descriptor_entry);
283
+ }
284
+
285
+ private:
286
+ u2 name_index;
287
+ u2 descriptor_index;
288
+ };
289
+
290
+ class base_ref_infot : public structured_pool_entryt
291
+ {
292
+ public:
293
+ explicit base_ref_infot (pool_entryt entry)
294
+ : structured_pool_entryt(entry)
295
+ {
296
+ static std::set<u1> info_tags = {
297
+ CONSTANT_Fieldref, CONSTANT_Methodref, CONSTANT_InterfaceMethodref};
298
+ PRECONDITION (info_tags.find (entry.tag ) != info_tags.end ());
299
+ class_index=entry.ref1 ;
300
+ name_and_type_index=entry.ref2 ;
301
+ }
302
+
303
+ u1 get_class_index () const { return class_index; }
304
+ u1 get_name_and_type_index () const { return name_and_type_index; }
305
+
306
+ name_and_type_infot get_name_and_type (pool_entry_lookupt pool_entry) const
307
+ {
308
+ const pool_entryt &name_and_type_entry =
309
+ pool_entry (name_and_type_index);
310
+
311
+ INVARIANT (
312
+ name_and_type_entry.tag == CONSTANT_NameAndType,
313
+ " name_and_typeindex did not correspond to a name_and_type in the constants "
314
+ " pool" );
315
+
316
+ return name_and_type_infot{name_and_type_entry};
317
+ }
318
+
319
+ class_infot get_class (pool_entry_lookupt pool_entry) const
320
+ {
321
+ const pool_entryt &class_entry =
322
+ pool_entry (class_index);
323
+
324
+ return class_infot{class_entry};
325
+ }
326
+
327
+ private:
328
+ u2 class_index;
329
+ u2 name_and_type_index;
330
+ };
331
+
213
332
bool java_bytecode_parsert::parse ()
214
333
{
215
334
try
0 commit comments