Skip to content

Commit 3e82864

Browse files
Set language options
1 parent 0db25c7 commit 3e82864

25 files changed

+189
-141
lines changed

jbmc/src/janalyzer/janalyzer_parse_options.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ void janalyzer_parse_optionst::get_command_line_options(optionst &options)
7777
exit(CPROVER_EXIT_USAGE_ERROR);
7878
}
7979

80+
parse_java_language_options(cmdline, options);
81+
8082
// check assertions
8183
if(cmdline.isset("no-assertions"))
8284
options.set_option("assertions", false);
@@ -350,7 +352,7 @@ int janalyzer_parse_optionst::doit()
350352

351353
try
352354
{
353-
goto_model = initialize_goto_model(cmdline, get_message_handler());
355+
goto_model = initialize_goto_model(cmdline, get_message_handler(), options);
354356
}
355357

356358
catch(const char *e)

jbmc/src/java_bytecode/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ SRC = bytecode_info.cpp \
3535
java_types.cpp \
3636
java_utils.cpp \
3737
load_method_by_regex.cpp \
38+
object_factory_parameters.cpp \
3839
mz_zip_archive.cpp \
3940
remove_exceptions.cpp \
4041
remove_instanceof.cpp \

jbmc/src/java_bytecode/java_bytecode_language.cpp

Lines changed: 76 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@ Author: Daniel Kroening, [email protected]
1010

1111
#include <string>
1212

13-
#include <util/symbol_table.h>
14-
#include <util/suffix.h>
15-
#include <util/config.h>
1613
#include <util/cmdline.h>
14+
#include <util/config.h>
1715
#include <util/expr_iterator.h>
16+
#include <util/invariant.h>
1817
#include <util/journalling_symbol_table.h>
18+
#include <util/options.h>
1919
#include <util/string2int.h>
20-
#include <util/invariant.h>
20+
#include <util/suffix.h>
21+
#include <util/symbol_table.h>
22+
2123
#include <json/json_parser.h>
2224

2325
#include <goto-programs/class_hierarchy.h>
@@ -39,97 +41,108 @@ Author: Daniel Kroening, [email protected]
3941
#include "expr2java.h"
4042
#include "load_method_by_regex.h"
4143

42-
/// Consume options that are java bytecode specific.
43-
/// \param Command:line options
44-
/// \return None
45-
void java_bytecode_languaget::get_language_options(const cmdlinet &cmd)
44+
/// Parse options that are java bytecode specific.
45+
/// \param cmd Command line
46+
/// \param [out] options The options object that will be updated.
47+
void parse_java_language_options(const cmdlinet &cmd, optionst &options)
4648
{
47-
assume_inputs_non_null=cmd.isset("java-assume-inputs-non-null");
48-
string_refinement_enabled = !cmd.isset("no-refine-strings");
49-
throw_runtime_exceptions =
50-
cmd.isset("java-throw-runtime-exceptions") || // will go away
51-
cmd.isset("throw-runtime-exceptions");
52-
assert_uncaught_exceptions = !cmd.isset("disable-uncaught-exception-check");
53-
throw_assertion_error = cmd.isset("throw-assertion-error");
54-
threading_support = cmd.isset("java-threading");
49+
options.set_option(
50+
"java-assume-inputs-non-null", cmd.isset("java-assume-inputs-non-null"));
51+
options.set_option(
52+
"throw-runtime-exceptions", cmd.isset("throw-runtime-exceptions"));
53+
options.set_option(
54+
"uncaught-exception-check", !cmd.isset("disable-uncaught-exception-check"));
55+
options.set_option(
56+
"throw-assertion-error", cmd.isset("throw-assertion-error"));
57+
options.set_option("java-threading", cmd.isset("java-threading"));
5558

56-
if(cmd.isset("java-max-input-array-length")) // will go away
57-
{
58-
object_factory_parameters.max_nondet_array_length =
59-
safe_string2size_t(cmd.get_value("java-max-input-array-length"));
60-
}
61-
if(cmd.isset("max-nondet-array-length"))
59+
if(cmd.isset("java-max-vla-length"))
6260
{
63-
object_factory_parameters.max_nondet_array_length =
64-
safe_string2size_t(cmd.get_value("max-nondet-array-length"));
61+
options.set_option(
62+
"java-max-vla-length", cmd.get_value("java-max-vla-length"));
6563
}
6664

67-
if(cmd.isset("java-max-input-tree-depth")) // will go away
68-
{
69-
object_factory_parameters.max_nondet_tree_depth =
70-
safe_string2size_t(cmd.get_value("java-max-input-tree-depth"));
71-
}
72-
if(cmd.isset("max-nondet-tree-depth"))
65+
options.set_option(
66+
"symex-driven-lazy-loading", cmd.isset("symex-driven-lazy-loading"));
67+
68+
if(cmd.isset("java-load-class"))
69+
options.set_option("java-load-class", cmd.get_values("java-load-class"));
70+
71+
if(cmd.isset("java-no-load-class"))
7372
{
74-
object_factory_parameters.max_nondet_tree_depth =
75-
safe_string2size_t(cmd.get_value("max-nondet-tree-depth"));
73+
options.set_option(
74+
"java-no-load-class", cmd.get_values("java-no-load-class"));
7675
}
77-
78-
if(cmd.isset("string-max-input-length")) // will go away
76+
if(cmd.isset("lazy-methods-extra-entry-point"))
7977
{
80-
object_factory_parameters.max_nondet_string_length =
81-
safe_string2size_t(cmd.get_value("string-max-input-length"));
78+
options.set_option(
79+
"lazy-methods-extra-entry-point",
80+
cmd.get_values("lazy-methods-extra-entry-point"));
8281
}
83-
if(cmd.isset("max-nondet-string-length"))
82+
if(cmd.isset("java-cp-include-files"))
8483
{
85-
object_factory_parameters.max_nondet_string_length =
86-
safe_string2size_t(cmd.get_value("max-nondet-string-length"));
84+
options.set_option(
85+
"java-cp-include-files", cmd.get_value("java-cp-include-files"));
8786
}
87+
}
8888

89-
object_factory_parameters.string_printable = cmd.isset("string-printable");
90-
if(cmd.isset("java-max-vla-length"))
91-
max_user_array_length =
92-
safe_string2size_t(cmd.get_value("java-max-vla-length"));
93-
if(cmd.isset("symex-driven-lazy-loading"))
89+
/// Consume options that are java bytecode specific.
90+
void java_bytecode_languaget::set_language_options(const optionst &options)
91+
{
92+
object_factory_parameters.set(options);
93+
94+
assume_inputs_non_null =
95+
options.get_bool_option("java-assume-inputs-non-null");
96+
string_refinement_enabled = options.get_bool_option("refine-strings");
97+
throw_runtime_exceptions =
98+
options.get_bool_option("throw-runtime-exceptions");
99+
assert_uncaught_exceptions =
100+
options.get_bool_option("uncaught-exception-check");
101+
throw_assertion_error = options.get_bool_option("throw-assertion-error");
102+
threading_support = options.get_bool_option("java-threading");
103+
max_user_array_length =
104+
options.get_unsigned_int_option("java-max-vla-length");
105+
106+
if(options.get_bool_option("symex-driven-lazy-loading"))
94107
lazy_methods_mode=LAZY_METHODS_MODE_EXTERNAL_DRIVER;
95-
else if(!cmd.isset("no-lazy-methods"))
108+
else if(options.get_bool_option("lazy-methods"))
96109
lazy_methods_mode=LAZY_METHODS_MODE_CONTEXT_INSENSITIVE;
97110
else
98111
lazy_methods_mode=LAZY_METHODS_MODE_EAGER;
99112

100113
if(throw_runtime_exceptions)
101114
{
102115
java_load_classes.insert(
103-
java_load_classes.end(),
104-
exception_needed_classes.begin(),
105-
exception_needed_classes.end());
116+
java_load_classes.end(),
117+
exception_needed_classes.begin(),
118+
exception_needed_classes.end());
106119
}
107-
if(cmd.isset("java-load-class"))
120+
121+
if(options.is_set("java-load-class"))
108122
{
109-
const auto &values = cmd.get_values("java-load-class");
123+
const auto &load_values = options.get_list_option("java-load-class");
110124
java_load_classes.insert(
111-
java_load_classes.end(), values.begin(), values.end());
125+
java_load_classes.end(), load_values.begin(), load_values.end());
112126
}
113-
if(cmd.isset("java-no-load-class"))
127+
if(options.is_set("java-no-load-class"))
114128
{
115-
const auto &values = cmd.get_values("java-no-load-class");
116-
no_load_classes = {values.begin(), values.end()};
129+
const auto &no_load_values = options.get_list_option("java-no-load-class");
130+
no_load_classes = {no_load_values.begin(), no_load_values.end()};
117131
}
118-
119-
const std::list<std::string> &extra_entry_points=
120-
cmd.get_values("lazy-methods-extra-entry-point");
132+
const std::list<std::string> &extra_entry_points =
133+
options.get_list_option("lazy-methods-extra-entry-point");
121134
std::transform(
122135
extra_entry_points.begin(),
123136
extra_entry_points.end(),
124137
std::back_inserter(extra_methods),
125138
build_load_method_by_regex);
126-
const auto &new_points = build_extra_entry_points(cmd);
139+
const auto &new_points = build_extra_entry_points(options);
127140
extra_methods.insert(
128141
extra_methods.end(), new_points.begin(), new_points.end());
129142

130-
if(cmd.isset("java-cp-include-files"))
143+
java_cp_include_files = options.get_option("java-cp-include-files");
144+
if(!java_cp_include_files.empty())
131145
{
132-
java_cp_include_files=cmd.get_value("java-cp-include-files");
133146
// load file list from JSON file
134147
if(java_cp_include_files[0]=='@')
135148
{
@@ -144,7 +157,7 @@ void java_bytecode_languaget::get_language_options(const cmdlinet &cmd)
144157
throw "the JSON file has a wrong format";
145158
jsont include_files=json_cp_config["jar"];
146159
if(!include_files.is_array())
147-
throw "the JSON file has a wrong format";
160+
throw "the JSON file has a wrong format";
148161

149162
// add jars from JSON config file to classpath
150163
for(const jsont &file_entry : include_files.array)
@@ -160,7 +173,7 @@ void java_bytecode_languaget::get_language_options(const cmdlinet &cmd)
160173
else
161174
java_cp_include_files=".*";
162175

163-
nondet_static = cmd.isset("nondet-static");
176+
nondet_static = options.get_bool_option("nondet-static");
164177

165178
language_options_initialized=true;
166179
}
@@ -1216,8 +1229,7 @@ java_bytecode_languaget::~java_bytecode_languaget()
12161229
/// specifying extra entry points. To provide a regex entry point, the command
12171230
/// line option `--lazy-methods-extra-entry-point` can be used directly.
12181231
std::vector<load_extra_methodst>
1219-
java_bytecode_languaget::build_extra_entry_points(
1220-
const cmdlinet &command_line) const
1232+
java_bytecode_languaget::build_extra_entry_points(const optionst &options) const
12211233
{
12221234
return {};
12231235
}

jbmc/src/java_bytecode/java_bytecode_language.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ enum lazy_methods_modet
9292
class java_bytecode_languaget:public languaget
9393
{
9494
public:
95-
virtual void get_language_options(const cmdlinet &) override;
95+
virtual void set_language_options(const optionst &) override;
9696

9797
virtual bool preprocess(
9898
std::istream &instream,
@@ -200,7 +200,7 @@ class java_bytecode_languaget:public languaget
200200

201201
private:
202202
virtual std::vector<load_extra_methodst>
203-
build_extra_entry_points(const cmdlinet &command_line) const;
203+
build_extra_entry_points(const optionst &) const;
204204
const std::unique_ptr<const select_pointer_typet> pointer_type_selector;
205205

206206
/// Maps synthetic method names on to the particular type of synthetic method
@@ -217,4 +217,6 @@ class java_bytecode_languaget:public languaget
217217

218218
std::unique_ptr<languaget> new_java_bytecode_language();
219219

220+
void parse_java_language_options(const cmdlinet &cmd, optionst &options);
221+
220222
#endif // CPROVER_JAVA_BYTECODE_JAVA_BYTECODE_LANGUAGE_H

jbmc/src/java_bytecode/java_class_loader_limit.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Author: Daniel Kroening, [email protected]
1313

1414
#include <json/json_parser.h>
1515

16+
#include <util/invariant.h>
17+
1618
/// Initializes class with either regex matcher or match set. If the string
1719
/// starts with an `@` it is treated as a path to a JSON file. Otherwise, it is
1820
/// treated as a regex.
@@ -48,8 +50,9 @@ Author: Daniel Kroening, [email protected]
4850
void java_class_loader_limitt::setup_class_load_limit(
4951
const std::string &java_cp_include_files)
5052
{
51-
if(java_cp_include_files.empty())
52-
throw "class regexp cannot be empty, `get_language_options` not called?";
53+
PRECONDITION(
54+
!java_cp_include_files.empty(),
55+
"class regexp cannot be empty, `set_language_options` not called?");
5356

5457
// '@' signals file reading with list of class files to load
5558
use_regex_match = java_cp_include_files[0] != '@';

jbmc/src/java_bytecode/object_factory_parameters.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ Author: Daniel Kroening, [email protected]
1414

1515
#include <util/irep.h>
1616

17+
class cmdlinet;
18+
class optionst;
19+
1720
#define MAX_NONDET_ARRAY_LENGTH_DEFAULT 5
1821
#define MAX_NONDET_STRING_LENGTH \
1922
static_cast<std::size_t>(std::numeric_limits<std::int32_t>::max())
@@ -23,18 +26,18 @@ Author: Daniel Kroening, [email protected]
2326
struct object_factory_parameterst final
2427
{
2528
/// Maximum value for the non-deterministically-chosen length of an array.
26-
size_t max_nondet_array_length=MAX_NONDET_ARRAY_LENGTH_DEFAULT;
29+
size_t max_nondet_array_length = MAX_NONDET_ARRAY_LENGTH_DEFAULT;
2730

2831
/// Maximum value for the non-deterministically-chosen length of a string.
29-
size_t max_nondet_string_length=MAX_NONDET_STRING_LENGTH;
32+
size_t max_nondet_string_length = MAX_NONDET_STRING_LENGTH;
3033

3134
/// Maximum depth for object hierarchy on input.
3235
/// Used to prevent object factory to loop infinitely during the
3336
/// generation of code that allocates/initializes data structures of recursive
3437
/// data types or unbounded depth. We bound the maximum number of times we
3538
/// dereference a pointer using a 'depth counter'. We set a pointer to null if
3639
/// such depth becomes >= than this maximum value.
37-
size_t max_nondet_tree_depth=MAX_NONDET_TREE_DEPTH;
40+
size_t max_nondet_tree_depth = MAX_NONDET_TREE_DEPTH;
3841

3942
/// To force a certain depth of non-null objects.
4043
/// The default is that objects are 'maybe null' up to the nondet tree depth.
@@ -53,6 +56,11 @@ struct object_factory_parameterst final
5356

5457
/// Function id, used as a prefix for identifiers of temporaries
5558
irep_idt function_id;
59+
60+
/// Assigns the parameters from given options
61+
void set(const optionst &);
5662
};
5763

64+
void parse_object_factory_options(const cmdlinet &, optionst &);
65+
5866
#endif

0 commit comments

Comments
 (0)