Skip to content

Commit fc2e8da

Browse files
author
Matthias Güdemann
committed
Document java_class_loader
1 parent c4cd791 commit fc2e8da

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

jbmc/src/java_bytecode/java_class_loader.cpp

Lines changed: 23 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,11 @@ 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 searching for `ID_overlay_class` in
111+
/// its list of annotations. TODO(nathan) give a short explanation about what
112+
/// overlay classes are.
113+
/// \param c: a `classt` object from a java byte code parse tree
114+
/// \return true if parsed class is an overlay class, else false
105115
static bool is_overlay_class(const java_bytecode_parse_treet::classt &c)
106116
{
107117
return java_bytecode_parse_treet::find_annotation(
@@ -228,6 +238,9 @@ java_class_loadert::get_parse_tree(
228238
return parse_trees;
229239
}
230240

241+
/// Load all class files from a .jar file, and store name of .jar in
242+
/// `classpath_entreies`.
243+
/// \param jar_path: the path for the .jar to load
231244
void java_class_loadert::load_entire_jar(
232245
const std::string &jar_path)
233246
{
@@ -280,6 +293,12 @@ java_class_loadert::jar_index_optcreft java_class_loadert::read_jar_file(
280293
return std::cref(jar_index);
281294
}
282295

296+
/// Convert a file name to the class name. Java interprets folders as packages,
297+
/// therefore a prefix of `./` is removed if necessary, and all `/` are
298+
/// converted to `.`. For example a class file `./com/diffblue/test.class` is
299+
/// converted to the class name `com.diffblue.test`.
300+
/// \param file: the name of the class file
301+
/// \return the file name converted to Java class name
283302
std::string java_class_loadert::file_to_class_name(const std::string &file)
284303
{
285304
std::string result=file;
@@ -307,6 +326,10 @@ std::string java_class_loadert::file_to_class_name(const std::string &file)
307326
return result;
308327
}
309328

329+
/// Convert a class name to a file name, does the inverse of \ref
330+
/// file_to_class_name.
331+
/// \param class_name: the name of the class
332+
/// \return the class name converted to file name
310333
std::string java_class_loadert::class_name_to_file(const irep_idt &class_name)
311334
{
312335
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)