Skip to content

Commit 8143eea

Browse files
author
Daniel Kroening
committed
unify jar list and classpath
1 parent 4dddd0c commit 8143eea

File tree

4 files changed

+33
-29
lines changed

4 files changed

+33
-29
lines changed

jbmc/src/java_bytecode/java_bytecode_language.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ Author: Daniel Kroening, [email protected]
3939
#include "expr2java.h"
4040
#include "load_method_by_regex.h"
4141

42+
/// Set up the classpath
43+
void java_bytecode_languaget::setup_classpath()
44+
{
45+
for(const auto &p : config.java.classpath)
46+
java_class_loader(p);
47+
}
48+
4249
/// Consume options that are java bytecode specific.
4350
/// \param Command:line options
4451
/// \return None
@@ -232,7 +239,7 @@ bool java_bytecode_languaget::parse(
232239
main_jar_classes.push_back(kv.first);
233240
}
234241
else
235-
java_class_loader.add_jar_file(path);
242+
java_class_loader.add_classpath_entry(path);
236243
}
237244
else
238245
UNREACHABLE;

jbmc/src/java_bytecode/java_bytecode_language.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,16 @@ class java_bytecode_languaget:public languaget
123123
lazy_methods_mode(lazy_methods_modet::LAZY_METHODS_MODE_EAGER),
124124
string_refinement_enabled(false),
125125
pointer_type_selector(std::move(pointer_type_selector))
126-
{}
126+
{
127+
setup_classpath();
128+
}
127129

128130
java_bytecode_languaget():
129131
java_bytecode_languaget(
130132
std::unique_ptr<select_pointer_typet>(new select_pointer_typet()))
131-
{}
132-
133+
{
134+
setup_classpath();
135+
}
133136

134137
bool from_expr(
135138
const exprt &expr,
@@ -162,6 +165,8 @@ class java_bytecode_languaget:public languaget
162165
symbol_table_baset &symbol_table) override;
163166

164167
protected:
168+
void setup_classpath();
169+
165170
void convert_single_method(
166171
const irep_idt &function_id,
167172
symbol_table_baset &symbol_table)

jbmc/src/java_bytecode/java_class_loader.cpp

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ Author: Daniel Kroening, [email protected]
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,11 @@ 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+
classpath_entries.push_back(path);
74+
}
75+
7276
optionalt<java_bytecode_parse_treet> java_class_loadert::get_class_from_jar(
7377
const irep_idt &class_name,
7478
const std::string &jar_file,
@@ -124,20 +128,8 @@ java_class_loadert::get_parse_tree(
124128
return parse_trees;
125129
}
126130

127-
// First add all given JAR files
128-
for(const auto &jar_file : jar_files)
129-
{
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)
131+
// Rummage through the class path
132+
for(const auto &cp_entry : classpath_entries)
141133
{
142134
if(has_suffix(cp_entry, ".jar"))
143135
{
@@ -234,12 +226,12 @@ void java_class_loadert::load_entire_jar(
234226
if(!jar_index)
235227
return;
236228

237-
jar_files.push_front(jar_path);
229+
classpath_entries.push_front(jar_path);
238230

239231
for(const auto &e : jar_index->get())
240232
operator()(e.first);
241233

242-
jar_files.pop_front();
234+
classpath_entries.pop_front();
243235
}
244236

245237
java_class_loadert::jar_index_optcreft java_class_loadert::read_jar_file(

jbmc/src/java_bytecode/java_class_loader.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,12 @@ class java_class_loadert:public messaget
7373
for(const auto &id : classes)
7474
java_load_classes.push_back(id);
7575
}
76-
void add_jar_file(const std::string &f)
77-
{
78-
jar_files.push_back(f);
79-
}
76+
77+
/// Appends an entry to the class path, used for loading classes. The
78+
/// argument may be
79+
/// 1) The name of a directory, used for searching for .class files
80+
/// 2) The name of a JAR file
81+
void add_classpath_entry(const std::string &);
8082

8183
static std::string file_to_class_name(const std::string &);
8284
static std::string class_name_to_file(const irep_idt &);
@@ -122,10 +124,8 @@ class java_class_loadert:public messaget
122124
/// information.
123125
std::string java_cp_include_files;
124126

125-
/// List of filesystem paths to .jar files that will be used, in the given
126-
/// order, to find and load a class, provided its name (see \ref
127-
/// get_parse_tree).
128-
std::list<std::string> jar_files;
127+
/// List of entries in the classpath
128+
std::list<std::string> classpath_entries;
129129

130130
/// Classes to be explicitly loaded
131131
std::vector<irep_idt> java_load_classes;

0 commit comments

Comments
 (0)