Skip to content

Commit 6dcfaca

Browse files
author
Matthias Güdemann
committed
Document java_class_loader
1 parent d1fbad3 commit 6dcfaca

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

jbmc/src/java_bytecode/java_class_loader.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ void java_class_loadert::add_classpath_entry(const std::string &path)
8181
}
8282
}
8383

84+
/// Load class from jar file.
85+
/// \param class_name: name of class to load in Java source format
86+
/// \param jar_file: path of the jar file
87+
/// \param jar_index: the index of the jar file
88+
/// \return optional value of parse tree, empty if class cannot be loaded
8489
optionalt<java_bytecode_parse_treet> java_class_loadert::get_class_from_jar(
8590
const irep_idt &class_name,
8691
const std::string &jar_file,
@@ -102,6 +107,10 @@ optionalt<java_bytecode_parse_treet> java_class_loadert::get_class_from_jar(
102107
return java_bytecode_parse(istream, get_message_handler());
103108
}
104109

110+
/// Check if class is an overlay class by inspecting the `ID_overlay_class`
111+
/// annotation.
112+
/// \param c: a `classt` object from a java byte code parse tree
113+
/// \return true if parsed class is an overlay class, else false
105114
static bool is_overlay_class(const java_bytecode_parse_treet::classt &c)
106115
{
107116
return java_bytecode_parse_treet::find_annotation(
@@ -228,6 +237,9 @@ java_class_loadert::get_parse_tree(
228237
return parse_trees;
229238
}
230239

240+
/// Load all class files from a .jar file, and store name of .jar in
241+
/// `classpath_entreies`.
242+
/// \param jar_path: the path for the .jar to load
231243
void java_class_loadert::load_entire_jar(
232244
const std::string &jar_path)
233245
{
@@ -280,6 +292,12 @@ java_class_loadert::jar_index_optcreft java_class_loadert::read_jar_file(
280292
return std::cref(jar_index);
281293
}
282294

295+
/// Convert a file name to the class name. Java interprets folders as packages,
296+
/// therefore a prefix of `./` is removed if necessary, and all `/` are
297+
/// converted to `.`. For example a class file `./com/diffblue/test.class` is
298+
/// converted to the class name `com.diffblue.test`.
299+
/// \param file: the name of the class file
300+
/// \return the file name converted to Java class name
283301
std::string java_class_loadert::file_to_class_name(const std::string &file)
284302
{
285303
std::string result=file;
@@ -307,6 +325,10 @@ std::string java_class_loadert::file_to_class_name(const std::string &file)
307325
return result;
308326
}
309327

328+
/// Convert a class name to a file name, does the inverse of \ref
329+
/// file_to_class_name.
330+
/// \param class_name: the name of the class
331+
/// \return the class name converted to file name
310332
std::string java_class_loadert::class_name_to_file(const irep_idt &class_name)
311333
{
312334
std::string result=id2string(class_name);

jbmc/src/java_bytecode/java_class_loader.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,19 @@ Author: Daniel Kroening, [email protected]
2222
#include "java_bytecode_parse_tree.h"
2323
#include "java_class_loader_limit.h"
2424

25+
/// Class responsible to load .class files. Either directly from a specific
26+
/// file, from a classpath specification or from a Java archive (JAR) file.
2527
class java_class_loadert:public messaget
2628
{
2729
public:
2830
/// A map associating logical class names with the name of the .class file
2931
/// implementing it for all classes inside a single JAR file
3032
typedef std::map<irep_idt, std::string> jar_indext;
3133

34+
/// A list of parse trees supporting overlay classes
3235
typedef std::list<java_bytecode_parse_treet> parse_tree_with_overlayst;
36+
/// A map from class names to list of parse tree where multiple entries can
37+
/// exist in case of overlay classes.
3338
typedef std::map<irep_idt, parse_tree_with_overlayst>
3439
parse_tree_with_overridest_mapt;
3540

@@ -54,6 +59,8 @@ class java_class_loadert:public messaget
5459
java_class_loader_limitt &class_loader_limit,
5560
const irep_idt &class_name);
5661

62+
/// Set the argument of the class loader limit \ref java_class_loader_limitt
63+
/// \param java_cp_include_files: argument string for java_class_loader_limit
5764
void set_java_cp_include_files(const std::string &java_cp_include_files)
5865
{
5966
this->java_cp_include_files = java_cp_include_files;

0 commit comments

Comments
 (0)