12
12
13
13
#include < util/config.h>
14
14
#include < util/language.h>
15
+ #include < util/options.h>
15
16
#include < util/suffix.h>
16
17
18
+ #include < goto-programs/lazy_goto_model.h>
19
+
17
20
#include < java_bytecode/java_bytecode_language.h>
18
21
19
22
// / Go through the process of loading, typechecking and finalising loading a
@@ -34,34 +37,55 @@ symbol_tablet load_java_class(
34
37
symbol_tablet load_java_class (
35
38
const std::string &java_class_name,
36
39
const std::string &class_path,
37
- std::unique_ptr<languaget> java_lang)
40
+ std::unique_ptr<languaget> && java_lang)
38
41
{
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
41
44
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);
42
55
43
56
// Configure the path loading
44
57
cmdlinet command_line;
45
58
command_line.set (" java-cp-include-files" , class_path);
46
59
config.java .classpath .clear ();
47
60
config.java .classpath .push_back (class_path);
48
61
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 ;
50
66
51
67
std::istringstream java_code_stream (" ignored" );
52
- null_message_handlert message_handler;
53
68
54
69
// 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" );
60
83
61
84
// Verify that the class was loaded
62
85
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);
65
89
REQUIRE (class_symbol.is_type );
66
90
const typet &class_type=class_symbol.type ;
67
91
REQUIRE (class_type.id ()==ID_struct);
@@ -70,5 +94,5 @@ symbol_tablet load_java_class(
70
94
// Check your working directory and the class path is correctly configured
71
95
// as this often indicates that one of these is wrong.
72
96
REQUIRE_FALSE (class_type.get_bool (ID_incomplete_class));
73
- return new_symbol_table ;
97
+ return std::move (maybe_goto_model-> symbol_table ) ;
74
98
}
0 commit comments