Skip to content

Commit a45f058

Browse files
author
Daniel Kroening
authored
Merge pull request #3052 from thk123/unit/add-load-java-class-goto-model-overload
Introduce overloads for getting a goto model out of load_java_class
2 parents f6666ad + 4b8a655 commit a45f058

File tree

2 files changed

+63
-30
lines changed

2 files changed

+63
-30
lines changed

jbmc/unit/java-testing-utils/load_java_class.cpp

Lines changed: 51 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818

1919
#include <goto-programs/lazy_goto_model.h>
2020

21-
#include <langapi/mode.h>
22-
2321
#include <java_bytecode/java_bytecode_language.h>
2422
#include <util/file_util.h>
2523

@@ -38,42 +36,41 @@ symbol_tablet load_java_class_lazy(
3836
const std::string &class_path,
3937
const std::string &main)
4038
{
41-
register_language(new_java_bytecode_language);
39+
std::unique_ptr<languaget> lang = new_java_bytecode_language();
4240

43-
return load_java_class(
44-
java_class_name, class_path, main, get_language_from_mode(ID_java));
41+
return load_java_class(java_class_name, class_path, main, std::move(lang));
4542
}
4643

47-
/// Go through the process of loading, type-checking and finalising loading a
48-
/// specific class file to build the symbol table.
49-
/// \param java_class_name: The name of the class file to load. It should not
50-
/// include the .class extension.
51-
/// \param class_path: The path to load the class from. Should be relative to
52-
/// the unit directory.
53-
/// \param main: The name of the main function or "" to use the default
54-
/// behaviour to find a main function.
55-
/// \return The symbol table that is generated by parsing this file.
44+
/// Returns the symbol table from
45+
/// \ref load_goto_model_from_java_class(const std::string &java_class_name, const std::string &class_path, const std::string &main) // NOLINT
5646
symbol_tablet load_java_class(
5747
const std::string &java_class_name,
5848
const std::string &class_path,
5949
const std::string &main)
6050
{
61-
free_form_cmdlinet command_line;
62-
command_line.add_flag("no-lazy-methods");
63-
command_line.add_flag("no-refine-strings");
64-
65-
register_language(new_java_bytecode_language);
51+
return load_goto_model_from_java_class(java_class_name, class_path, main)
52+
.get_symbol_table();
53+
}
6654

67-
return load_java_class(
68-
java_class_name,
69-
class_path,
70-
main,
71-
get_language_from_mode(ID_java),
72-
command_line);
55+
/// Returns the symbol table from \ref load_goto_model_from_java_class
56+
symbol_tablet load_java_class(
57+
const std::string &java_class_name,
58+
const std::string &class_path,
59+
const std::string &main,
60+
std::unique_ptr<languaget> &&java_lang,
61+
const cmdlinet &command_line)
62+
{
63+
return load_goto_model_from_java_class(
64+
java_class_name,
65+
class_path,
66+
main,
67+
std::move(java_lang),
68+
command_line)
69+
.get_symbol_table();
7370
}
7471

75-
/// Go through the process of loading, type-checking and finalising loading a
76-
/// specific class file to build the symbol table.
72+
/// Go through the process of loading, type-checking and finalising a
73+
/// specific class file to build a goto model from it.
7774
/// \param java_class_name: The name of the class file to load. It should not
7875
/// include the .class extension.
7976
/// \param class_path: The path to load the class from. Should be relative to
@@ -82,8 +79,11 @@ symbol_tablet load_java_class(
8279
/// behaviour to find a main function.
8380
/// \param java_lang: The language implementation to use for the loading,
8481
/// which will be destroyed by this function.
85-
/// \return The symbol table that is generated by parsing this file.
86-
symbol_tablet load_java_class(
82+
/// \param command_line: The command line used to configure the provided
83+
/// language
84+
/// \return The goto model containing both the functions and the symbol table
85+
/// from loading this class.
86+
goto_modelt load_goto_model_from_java_class(
8787
const std::string &java_class_name,
8888
const std::string &class_path,
8989
const std::string &main,
@@ -153,9 +153,12 @@ symbol_tablet load_java_class(
153153
// Check your working directory and the class path is correctly configured
154154
// as this often indicates that one of these is wrong.
155155
REQUIRE_FALSE(class_type.get_bool(ID_incomplete_class));
156-
return std::move(maybe_goto_model->symbol_table);
156+
return std::move(*maybe_goto_model);
157157
}
158158

159+
/// Returns the symbol table from \ref load_goto_model_from_java_class
160+
/// with the command line set to be disabling lazy loading and string
161+
/// refinement
159162
symbol_tablet load_java_class(
160163
const std::string &java_class_name,
161164
const std::string &class_path,
@@ -173,3 +176,21 @@ symbol_tablet load_java_class(
173176
return load_java_class(
174177
java_class_name, class_path, main, std::move(java_lang), command_line);
175178
}
179+
180+
/// See \ref load_goto_model_from_java_class
181+
/// With the command line configured to disable lazy loading and string
182+
/// refinement and the language set to be the default java_bytecode language
183+
goto_modelt load_goto_model_from_java_class(
184+
const std::string &java_class_name,
185+
const std::string &class_path,
186+
const std::string &main)
187+
{
188+
free_form_cmdlinet command_line;
189+
command_line.add_flag("no-lazy-methods");
190+
command_line.add_flag("no-refine-strings");
191+
192+
std::unique_ptr<languaget> lang = new_java_bytecode_language();
193+
194+
return load_goto_model_from_java_class(
195+
java_class_name, class_path, main, std::move(lang), command_line);
196+
}

jbmc/unit/java-testing-utils/load_java_class.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ symbol_tablet load_java_class(
2525
const std::string &class_path,
2626
const std::string &main = "");
2727

28+
goto_modelt load_goto_model_from_java_class(
29+
const std::string &java_class_name,
30+
const std::string &class_path,
31+
const std::string &main = "");
32+
2833
symbol_tablet load_java_class(
2934
const std::string &java_class_name,
3035
const std::string &class_path,
@@ -38,6 +43,13 @@ symbol_tablet load_java_class(
3843
std::unique_ptr<languaget> &&java_lang,
3944
const cmdlinet &command_line);
4045

46+
goto_modelt load_goto_model_from_java_class(
47+
const std::string &java_class_name,
48+
const std::string &class_path,
49+
const std::string &main,
50+
std::unique_ptr<languaget> &&java_lang,
51+
const cmdlinet &command_line);
52+
4153
symbol_tablet load_java_class_lazy(
4254
const std::string &java_class_name,
4355
const std::string &class_path,

0 commit comments

Comments
 (0)