Skip to content

Commit cb09d8e

Browse files
Fix new tests to use lazy loading
1 parent 166563f commit cb09d8e

File tree

3 files changed

+43
-14
lines changed

3 files changed

+43
-14
lines changed

src/goto-programs/lazy_goto_model.h

+5
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ class lazy_goto_modelt
7171
/// Eagerly loads all functions from the symbol table.
7272
void load_all_functions() const;
7373

74+
language_filet &add_language_file(const std::string &filename)
75+
{
76+
return language_files.add_file(filename);
77+
}
78+
7479
/// The model returned here has access to the functions we've already
7580
/// loaded but is frozen in the sense that, with regard to the facility to
7681
/// load new functions, it has let it go.

unit/testing-utils/load_java_class.cpp

+37-13
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@
1212

1313
#include <util/config.h>
1414
#include <util/language.h>
15+
#include <util/options.h>
1516
#include <util/suffix.h>
1617

18+
#include <goto-programs/lazy_goto_model.h>
19+
1720
#include <java_bytecode/java_bytecode_language.h>
1821

1922
/// Go through the process of loading, typechecking and finalising loading a
@@ -34,34 +37,55 @@ symbol_tablet load_java_class(
3437
symbol_tablet load_java_class(
3538
const std::string &java_class_name,
3639
const std::string &class_path,
37-
std::unique_ptr<languaget> java_lang)
40+
std::unique_ptr<languaget> &&java_lang)
3841
{
39-
// We don't expect the .class suffix to allow us to check the name of the
40-
// class
42+
// We expect the name of the class without the .class suffix to allow us to
43+
// check it
4144
PRECONDITION(!has_suffix(java_class_name, ".class"));
45+
std::string filename=java_class_name + ".class";
46+
47+
// Construct a lazy_goto_modelt
48+
null_message_handlert message_handler;
49+
lazy_goto_modelt lazy_goto_model(
50+
[] (goto_functionst::goto_functiont &function, symbol_tablet &symbol_table)
51+
{ },
52+
[] (goto_modelt &goto_model)
53+
{ return false; },
54+
message_handler);
4255

4356
// Configure the path loading
4457
cmdlinet command_line;
4558
command_line.set("java-cp-include-files", class_path);
4659
config.java.classpath.clear();
4760
config.java.classpath.push_back(class_path);
4861

49-
symbol_tablet new_symbol_table;
62+
// Add the language to the model
63+
language_filet &lf=lazy_goto_model.add_language_file(filename);
64+
lf.language=std::move(java_lang);
65+
languaget &language=*lf.language;
5066

5167
std::istringstream java_code_stream("ignored");
52-
null_message_handlert message_handler;
5368

5469
// Configure the language, load the class files
55-
java_lang->get_language_options(command_line);
56-
java_lang->set_message_handler(message_handler);
57-
java_lang->parse(java_code_stream, java_class_name + ".class");
58-
java_lang->typecheck(new_symbol_table, "");
59-
java_lang->final(new_symbol_table);
70+
language.set_message_handler(message_handler);
71+
language.get_language_options(command_line);
72+
language.parse(java_code_stream, filename);
73+
language.typecheck(lazy_goto_model.symbol_table, "");
74+
language.generate_support_functions(lazy_goto_model.symbol_table);
75+
language.final(lazy_goto_model.symbol_table);
76+
77+
lazy_goto_model.load_all_functions();
78+
79+
std::unique_ptr<goto_modelt> maybe_goto_model=
80+
lazy_goto_modelt::process_whole_model_and_freeze(
81+
std::move(lazy_goto_model));
82+
INVARIANT(maybe_goto_model, "Freezing lazy_goto_model failed");
6083

6184
// Verify that the class was loaded
6285
const std::string class_symbol_name="java::"+java_class_name;
63-
REQUIRE(new_symbol_table.has_symbol(class_symbol_name));
64-
const symbolt &class_symbol=*new_symbol_table.lookup(class_symbol_name);
86+
REQUIRE(maybe_goto_model->symbol_table.has_symbol(class_symbol_name));
87+
const symbolt &class_symbol=
88+
*maybe_goto_model->symbol_table.lookup(class_symbol_name);
6589
REQUIRE(class_symbol.is_type);
6690
const typet &class_type=class_symbol.type;
6791
REQUIRE(class_type.id()==ID_struct);
@@ -70,5 +94,5 @@ symbol_tablet load_java_class(
7094
// Check your working directory and the class path is correctly configured
7195
// as this often indicates that one of these is wrong.
7296
REQUIRE_FALSE(class_type.get_bool(ID_incomplete_class));
73-
return new_symbol_table;
97+
return std::move(maybe_goto_model->symbol_table);
7498
}

unit/testing-utils/load_java_class.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ symbol_tablet load_java_class(
2424
symbol_tablet load_java_class(
2525
const std::string &java_class_name,
2626
const std::string &class_path,
27-
std::unique_ptr<languaget> java_lang);
27+
std::unique_ptr<languaget> &&java_lang);
2828

2929
#endif // CPROVER_TESTING_UTILS_LOAD_JAVA_CLASS_H

0 commit comments

Comments
 (0)