@@ -132,11 +132,10 @@ void lazy_class_to_declared_symbols_mapt::reinitialize()
132
132
map.clear ();
133
133
}
134
134
135
- // / Consume options that are java bytecode specific.
136
- void java_bytecode_languaget::set_language_options (const optionst &options)
135
+ java_bytecode_language_optionst::java_bytecode_language_optionst (
136
+ const optionst &options,
137
+ messaget &log)
137
138
{
138
- object_factory_parameters.set (options);
139
-
140
139
assume_inputs_non_null =
141
140
options.get_bool_option (" java-assume-inputs-non-null" );
142
141
string_refinement_enabled = options.get_bool_option (" refine-strings" );
@@ -182,9 +181,6 @@ void java_bytecode_languaget::set_language_options(const optionst &options)
182
181
extra_entry_points.end (),
183
182
std::back_inserter (extra_methods),
184
183
build_load_method_by_regex);
185
- const auto &new_points = build_extra_entry_points (options);
186
- extra_methods.insert (
187
- extra_methods.end (), new_points.begin (), new_points.end ());
188
184
189
185
java_cp_include_files = options.get_option (" java-cp-include-files" );
190
186
if (!java_cp_include_files.empty ())
@@ -195,7 +191,7 @@ void java_bytecode_languaget::set_language_options(const optionst &options)
195
191
jsont json_cp_config;
196
192
if (parse_json (
197
193
java_cp_include_files.substr (1 ),
198
- get_message_handler (),
194
+ log. get_message_handler (),
199
195
json_cp_config))
200
196
throw " cannot read JSON input configuration for JAR loading" ;
201
197
@@ -224,17 +220,18 @@ void java_bytecode_languaget::set_language_options(const optionst &options)
224
220
{
225
221
const std::string filename = options.get_option (" static-values" );
226
222
jsont tmp_json;
227
- if (parse_json (filename, *message_handler , tmp_json))
223
+ if (parse_json (filename, log. get_message_handler () , tmp_json))
228
224
{
229
- warning () << " Provided JSON file for static-values cannot be parsed; it"
230
- << " will be ignored." << messaget::eom;
225
+ log.warning ()
226
+ << " Provided JSON file for static-values cannot be parsed; it"
227
+ << " will be ignored." << messaget::eom;
231
228
}
232
229
else
233
230
{
234
231
if (!tmp_json.is_object ())
235
232
{
236
- warning () << " Provided JSON file for static-values is not a JSON "
237
- << " object; it will be ignored." << messaget::eom;
233
+ log. warning () << " Provided JSON file for static-values is not a JSON "
234
+ << " object; it will be ignored." << messaget::eom;
238
235
}
239
236
else
240
237
static_values_json = std::move (to_json_object (tmp_json));
@@ -246,8 +243,18 @@ void java_bytecode_languaget::set_language_options(const optionst &options)
246
243
247
244
if (options.is_set (" context-include" ) || options.is_set (" context-exclude" ))
248
245
method_context = get_context (options);
246
+ }
249
247
250
- language_options_initialized=true ;
248
+ // / Consume options that are java bytecode specific.
249
+ void java_bytecode_languaget::set_language_options (const optionst &options)
250
+ {
251
+ object_factory_parameters.set (options);
252
+ language_options = java_bytecode_language_optionst{options, *this };
253
+ const auto &new_points = build_extra_entry_points (options);
254
+ language_options->extra_methods .insert (
255
+ language_options->extra_methods .end (),
256
+ new_points.begin (),
257
+ new_points.end ());
251
258
}
252
259
253
260
std::set<std::string> java_bytecode_languaget::extensions () const
@@ -283,17 +290,18 @@ bool java_bytecode_languaget::parse(
283
290
std::istream &,
284
291
const std::string &path)
285
292
{
286
- PRECONDITION (language_options_initialized );
293
+ PRECONDITION (language_options. has_value () );
287
294
288
295
java_class_loader.clear_classpath ();
289
296
290
297
for (const auto &p : config.java .classpath )
291
298
java_class_loader.add_classpath_entry (p);
292
299
293
300
java_class_loader.set_message_handler (get_message_handler ());
294
- java_class_loader.set_java_cp_include_files (java_cp_include_files);
295
- java_class_loader.add_load_classes (java_load_classes);
296
- if (string_refinement_enabled)
301
+ java_class_loader.set_java_cp_include_files (
302
+ language_options->java_cp_include_files );
303
+ java_class_loader.add_load_classes (language_options->java_load_classes );
304
+ if (language_options->string_refinement_enabled )
297
305
{
298
306
string_preprocess.initialize_known_type_table ();
299
307
@@ -314,8 +322,7 @@ bool java_bytecode_languaget::parse(
314
322
{
315
323
// build an object to potentially limit which classes are loaded
316
324
java_class_loader_limitt class_loader_limit (
317
- get_message_handler (),
318
- java_cp_include_files);
325
+ get_message_handler (), language_options->java_cp_include_files );
319
326
if (config.java .main_class .empty ())
320
327
{
321
328
// If we have an entry method, we can derive a main class.
@@ -331,8 +338,12 @@ bool java_bytecode_languaget::parse(
331
338
std::string manifest_main_class = manifest[" Main-Class" ];
332
339
333
340
// if the manifest declares a Main-Class line, we got a main class
334
- if (!manifest_main_class.empty () && !ignore_manifest_main_class)
341
+ if (
342
+ !manifest_main_class.empty () &&
343
+ !language_options->ignore_manifest_main_class )
344
+ {
335
345
main_class = manifest_main_class;
346
+ }
336
347
}
337
348
}
338
349
else
@@ -725,7 +736,7 @@ bool java_bytecode_languaget::typecheck(
725
736
symbol_tablet &symbol_table,
726
737
const std::string &)
727
738
{
728
- PRECONDITION (language_options_initialized );
739
+ PRECONDITION (language_options. has_value () );
729
740
// There are various cases in the Java front-end where pre-existing symbols
730
741
// from a previous load are not handled. We just rule this case out for now;
731
742
// a user wishing to ensure a particular class is loaded should use
@@ -738,7 +749,7 @@ bool java_bytecode_languaget::typecheck(
738
749
739
750
java_internal_additions (symbol_table);
740
751
741
- if (string_refinement_enabled)
752
+ if (language_options-> string_refinement_enabled )
742
753
string_preprocess.initialize_conversion_table ();
743
754
744
755
// Must load java.lang.Object first to avoid stubbing
@@ -748,15 +759,14 @@ bool java_bytecode_languaget::typecheck(
748
759
java_class_loader.get_class_with_overlays_map ().find (" java.lang.Object" );
749
760
if (it != java_class_loader.get_class_with_overlays_map ().end ())
750
761
{
751
- if (
752
- java_bytecode_convert_class (
753
- it->second ,
754
- symbol_table,
755
- get_message_handler (),
756
- max_user_array_length,
757
- method_bytecode,
758
- string_preprocess,
759
- no_load_classes))
762
+ if (java_bytecode_convert_class (
763
+ it->second ,
764
+ symbol_table,
765
+ get_message_handler (),
766
+ language_options->max_user_array_length ,
767
+ method_bytecode,
768
+ string_preprocess,
769
+ language_options->no_load_classes ))
760
770
{
761
771
return true ;
762
772
}
@@ -769,15 +779,14 @@ bool java_bytecode_languaget::typecheck(
769
779
if (class_trees.second .front ().parsed_class .name .empty ())
770
780
continue ;
771
781
772
- if (
773
- java_bytecode_convert_class (
774
- class_trees.second ,
775
- symbol_table,
776
- get_message_handler (),
777
- max_user_array_length,
778
- method_bytecode,
779
- string_preprocess,
780
- no_load_classes))
782
+ if (java_bytecode_convert_class (
783
+ class_trees.second ,
784
+ symbol_table,
785
+ get_message_handler (),
786
+ language_options->max_user_array_length ,
787
+ method_bytecode,
788
+ string_preprocess,
789
+ language_options->no_load_classes ))
781
790
{
782
791
return true ;
783
792
}
@@ -852,7 +861,7 @@ bool java_bytecode_languaget::typecheck(
852
861
for (java_bytecode_parse_treet &parse_tree : class_to_trees.second )
853
862
{
854
863
generate_constant_global_variables (
855
- parse_tree, symbol_table, string_refinement_enabled);
864
+ parse_tree, symbol_table, language_options-> string_refinement_enabled );
856
865
}
857
866
}
858
867
status () << " Java: added "
@@ -888,14 +897,14 @@ bool java_bytecode_languaget::typecheck(
888
897
create_static_initializer_symbols (
889
898
symbol_table,
890
899
synthetic_methods,
891
- threading_support,
892
- static_values_json.has_value ());
900
+ language_options-> threading_support ,
901
+ language_options-> static_values_json .has_value ());
893
902
894
903
lazy_class_to_declared_symbols_mapt class_to_declared_symbols;
895
904
896
905
// Now incrementally elaborate methods
897
906
// that are reachable from this entry point.
898
- switch (lazy_methods_mode)
907
+ switch (language_options-> lazy_methods_mode )
899
908
{
900
909
case LAZY_METHODS_MODE_CONTEXT_INSENSITIVE:
901
910
// ci = context-insensitive
@@ -940,15 +949,17 @@ bool java_bytecode_languaget::typecheck(
940
949
// now instrument runtime exceptions
941
950
java_bytecode_instrument (
942
951
symbol_table,
943
- throw_runtime_exceptions,
952
+ language_options-> throw_runtime_exceptions ,
944
953
get_message_handler ());
945
954
946
955
// now typecheck all
947
956
bool res = java_bytecode_typecheck (
948
- symbol_table, get_message_handler (), string_refinement_enabled);
957
+ symbol_table,
958
+ get_message_handler (),
959
+ language_options->string_refinement_enabled );
949
960
950
961
// now instrument thread-blocks and synchronized methods.
951
- if (threading_support)
962
+ if (language_options-> threading_support )
952
963
{
953
964
convert_threadblock (symbol_table);
954
965
convert_synchronized_methods (symbol_table, get_message_handler ());
@@ -960,7 +971,7 @@ bool java_bytecode_languaget::typecheck(
960
971
bool java_bytecode_languaget::generate_support_functions (
961
972
symbol_tablet &symbol_table)
962
973
{
963
- PRECONDITION (language_options_initialized );
974
+ PRECONDITION (language_options. has_value () );
964
975
965
976
symbol_table_buildert symbol_table_builder =
966
977
symbol_table_buildert::wrap (symbol_table);
@@ -990,16 +1001,16 @@ bool java_bytecode_languaget::generate_support_functions(
990
1001
symbol_table_builder,
991
1002
main_class,
992
1003
get_message_handler (),
993
- assume_inputs_non_null,
994
- assert_uncaught_exceptions,
1004
+ language_options-> assume_inputs_non_null ,
1005
+ language_options-> assert_uncaught_exceptions ,
995
1006
object_factory_parameters,
996
1007
get_pointer_type_selector (),
997
- string_refinement_enabled,
1008
+ language_options-> string_refinement_enabled ,
998
1009
[&](const symbolt &function, symbol_table_baset &symbol_table) {
999
1010
return java_build_arguments (
1000
1011
function,
1001
1012
symbol_table,
1002
- assume_inputs_non_null,
1013
+ language_options-> assume_inputs_non_null ,
1003
1014
object_factory_parameters,
1004
1015
get_pointer_type_selector (),
1005
1016
get_message_handler ());
@@ -1040,9 +1051,9 @@ bool java_bytecode_languaget::do_ci_lazy_method_conversion(
1040
1051
symbol_table,
1041
1052
main_class,
1042
1053
main_jar_classes,
1043
- extra_methods,
1054
+ language_options-> extra_methods ,
1044
1055
java_class_loader,
1045
- java_load_classes,
1056
+ language_options-> java_load_classes ,
1046
1057
get_pointer_type_selector (),
1047
1058
get_message_handler (),
1048
1059
synthetic_methods);
@@ -1105,13 +1116,15 @@ void java_bytecode_languaget::convert_lazy_method(
1105
1116
java_bytecode_instrument_symbol (
1106
1117
symbol_table,
1107
1118
symbol_table.get_writeable_ref (function_id),
1108
- throw_runtime_exceptions,
1119
+ language_options-> throw_runtime_exceptions ,
1109
1120
get_message_handler ());
1110
1121
}
1111
1122
1112
1123
// now typecheck this function
1113
1124
java_bytecode_typecheck_updated_symbols (
1114
- symbol_table, get_message_handler (), string_refinement_enabled);
1125
+ symbol_table,
1126
+ get_message_handler (),
1127
+ language_options->string_refinement_enabled );
1115
1128
}
1116
1129
1117
1130
// / Notify ci_lazy_methods, if present, of any static function calls made by
@@ -1216,21 +1229,21 @@ bool java_bytecode_languaget::convert_single_method(
1216
1229
switch (synthetic_method_it->second )
1217
1230
{
1218
1231
case synthetic_method_typet::STATIC_INITIALIZER_WRAPPER:
1219
- if (threading_support)
1232
+ if (language_options-> threading_support )
1220
1233
writable_symbol.value = get_thread_safe_clinit_wrapper_body (
1221
1234
function_id,
1222
1235
symbol_table,
1223
- nondet_static,
1224
- static_values_json.has_value (),
1236
+ language_options-> nondet_static ,
1237
+ language_options-> static_values_json .has_value (),
1225
1238
object_factory_parameters,
1226
1239
get_pointer_type_selector (),
1227
1240
get_message_handler ());
1228
1241
else
1229
1242
writable_symbol.value = get_clinit_wrapper_body (
1230
1243
function_id,
1231
1244
symbol_table,
1232
- nondet_static,
1233
- static_values_json.has_value (),
1245
+ language_options-> nondet_static ,
1246
+ language_options-> static_values_json .has_value (),
1234
1247
object_factory_parameters,
1235
1248
get_pointer_type_selector (),
1236
1249
get_message_handler ());
@@ -1242,13 +1255,14 @@ bool java_bytecode_languaget::convert_single_method(
1242
1255
INVARIANT (
1243
1256
class_name, " user_specified_clinit must be declared by a class." );
1244
1257
INVARIANT (
1245
- static_values_json.has_value (), " static-values JSON must be available" );
1258
+ language_options->static_values_json .has_value (),
1259
+ " static-values JSON must be available" );
1246
1260
writable_symbol.value = get_user_specified_clinit_body (
1247
1261
*class_name,
1248
- *static_values_json,
1262
+ *language_options-> static_values_json ,
1249
1263
symbol_table,
1250
1264
needed_lazy_methods,
1251
- max_user_array_length,
1265
+ language_options-> max_user_array_length ,
1252
1266
references,
1253
1267
class_to_declared_symbols.get (symbol_table));
1254
1268
break ;
@@ -1301,13 +1315,13 @@ bool java_bytecode_languaget::convert_single_method(
1301
1315
cmb->get ().method ,
1302
1316
symbol_table,
1303
1317
get_message_handler (),
1304
- max_user_array_length,
1305
- throw_assertion_error,
1318
+ language_options-> max_user_array_length ,
1319
+ language_options-> throw_assertion_error ,
1306
1320
std::move (needed_lazy_methods),
1307
1321
string_preprocess,
1308
1322
class_hierarchy,
1309
- threading_support,
1310
- method_context);
1323
+ language_options-> threading_support ,
1324
+ language_options-> method_context );
1311
1325
INVARIANT (declaring_class (symbol), " Method must have a declaring class." );
1312
1326
return false ;
1313
1327
}
0 commit comments