23 const std::string &path,
30 if(std::ifstream(path).good())
37 log.warning() <<
"Warning: failed to access JAR file `" << path <<
"'"
43 if(std::filesystem::is_directory(path))
50 log.warning() <<
"Warning: failed to access directory `" << path <<
"'"
64 std::string result = file;
69 result.resize(result.size() - 6);
75 result = std::string(result, 2, std::string::npos);
78 result = std::string(result, 2, std::string::npos);
82 for(std::string::iterator it = result.begin(); it != result.end(); it++)
96 std::string result =
id2string(class_name);
99 for(std::string::iterator it = result.begin(); it != result.end(); it++)
115 std::string result =
id2string(class_name);
118 for(std::string::iterator it = result.begin(); it != result.end(); it++)
140 switch(cp_entry.
kind)
142 case classpath_entryt::JAR:
145 case classpath_entryt::DIRECTORY:
157 std::optional<java_bytecode_parse_treet>
160 const std::string &jar_file,
170 if(!data.has_value())
173 log.debug() <<
"Getting class '" << class_name <<
"' from JAR " << jar_file
176 std::istringstream istream(*data);
179 catch(
const std::runtime_error &)
181 log.error() <<
"failed to open JAR file '" << jar_file <<
"'"
192 std::optional<java_bytecode_parse_treet>
195 const std::string &path,
200 const std::string full_path =
201 std::filesystem::path(path).append(class_file).string();
203 if(std::ifstream(full_path))
206 log.debug() <<
"Getting class '" << class_name <<
"' from file "
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
void add_classpath_entry(const std::string &, message_handlert &)
Appends an entry to the class path, used for loading classes.
std::optional< java_bytecode_parse_treet > get_class_from_jar(const irep_idt &class_name, const std::string &jar_file, message_handlert &)
attempt to load a class from a given jar file
jar_poolt jar_pool
a cache for jar_filet, by path name
std::optional< java_bytecode_parse_treet > load_class(const irep_idt &class_name, const classpath_entryt &, message_handlert &)
attempt to load a class from a classpath_entry
static std::string class_name_to_os_file(const irep_idt &)
Convert a class name to a file name, with OS-dependent syntax.
std::optional< java_bytecode_parse_treet > get_class_from_directory(const irep_idt &class_name, const std::string &path, message_handlert &)
attempt to load a class from a given directory
static std::string class_name_to_jar_file(const irep_idt &)
Convert a class name to a file name, does the inverse of file_to_class_name.
std::list< classpath_entryt > classpath_entries
List of entries in the classpath.
static std::string file_to_class_name(const std::string &)
Convert a file name to the class name.
Class that provides messages with a built-in verbosity 'level'.
bool has_prefix(const std::string &s, const std::string &prefix)
const std::string & id2string(const irep_idt &d)
std::optional< java_bytecode_parse_treet > java_bytecode_parse(std::istream &istream, const irep_idt &class_name, message_handlert &message_handler, bool skip_instructions)
Attempt to parse a Java class from the given stream.
#define UNREACHABLE
This should be used to mark dead code.
An entry in the classpath.
bool has_suffix(const std::string &s, const std::string &suffix)