Skip to content

Commit dd1ee91

Browse files
author
Daniel Kroening
committed
the main_class is now remembered in the symbol table
1 parent f212624 commit dd1ee91

File tree

4 files changed

+23
-10
lines changed

4 files changed

+23
-10
lines changed

src/java_bytecode/ci_lazy_methods.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ bool ci_lazy_methodst::operator()(
6161
std::vector<irep_idt> method_worklist2;
6262

6363
auto main_function=
64-
get_main_symbol(symbol_table, main_class, get_message_handler(), true);
64+
get_main_symbol(symbol_table, get_message_handler(), true);
65+
6566
if(main_function.stop_convert)
6667
{
6768
// Failed, mark all functions in the given main class(es)

src/java_bytecode/java_bytecode_language.cpp

+13-2
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,18 @@ bool java_bytecode_languaget::typecheck(
236236
symbol_table, get_message_handler(), string_refinement_enabled))
237237
return true;
238238

239+
// remember the main class, if any
240+
if(!main_class.empty())
241+
{
242+
symbolt main_class_symbol;
243+
main_class_symbol.name="java_main_class";
244+
main_class_symbol.base_name=main_class_symbol.name;
245+
main_class_symbol.value.id(ID_string_constant);
246+
main_class_symbol.value.set(ID_value, main_class);
247+
main_class_symbol.mode=ID_java;
248+
symbol_table.move(main_class_symbol);
249+
}
250+
239251
return false;
240252
}
241253

@@ -368,15 +380,14 @@ bool java_bytecode_languaget::final(symbol_tablet &symbol_table)
368380
replace_string_methods(symbol_table);
369381

370382
main_function_resultt res=
371-
get_main_symbol(symbol_table, main_class, get_message_handler());
383+
get_main_symbol(symbol_table, get_message_handler());
372384
if(res.stop_convert)
373385
return res.error_found;
374386

375387
// generate the test harness in __CPROVER__start and a call the entry point
376388
return
377389
java_entry_point(
378390
symbol_table,
379-
main_class,
380391
get_message_handler(),
381392
assume_inputs_non_null,
382393
max_nondet_array_length,

src/java_bytecode/java_entry_point.cpp

+8-5
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,6 @@ void java_record_outputs(
322322

323323
main_function_resultt get_main_symbol(
324324
symbol_tablet &symbol_table,
325-
const irep_idt &main_class,
326325
message_handlert &message_handler,
327326
bool allow_no_body)
328327
{
@@ -362,7 +361,7 @@ main_function_resultt get_main_symbol(
362361
// check if it has a body
363362
if(symbol.value.is_nil() && !allow_no_body)
364363
{
365-
message.error() << "main method `" << main_class
364+
message.error() << "main method `" << symbol.display_name()
366365
<< "' has no body" << messaget::eom;
367366
res.main_function=symbol;
368367
res.error_found=true;
@@ -375,15 +374,20 @@ main_function_resultt get_main_symbol(
375374
// no function given, we look for the main class
376375
assert(config.main=="");
377376

377+
symbol_tablet::symbolst::const_iterator s_it=
378+
symbol_table.symbols.find("java_main_class");
379+
378380
// are we given a main class?
379-
if(main_class.empty())
381+
if(s_it==symbol_table.symbols.end())
380382
{
381383
res.main_function=symbol;
382384
res.error_found=false;
383385
res.stop_convert=true;
384386
return res; // silently ignore
385387
}
386388

389+
irep_idt main_class=s_it->second.value.get(ID_value);
390+
387391
std::string entry_method=
388392
id2string(main_class)+".main";
389393

@@ -478,7 +482,6 @@ main_function_resultt get_main_symbol(
478482
/// \returns true if error occurred on entry point search
479483
bool java_entry_point(
480484
symbol_tablet &symbol_table,
481-
const irep_idt &main_class,
482485
message_handlert &message_handler,
483486
bool assume_init_pointers_not_null,
484487
size_t max_nondet_array_length,
@@ -492,7 +495,7 @@ bool java_entry_point(
492495

493496
messaget message(message_handler);
494497
main_function_resultt res=
495-
get_main_symbol(symbol_table, main_class, message_handler);
498+
get_main_symbol(symbol_table, message_handler);
496499
if(res.stop_convert)
497500
return res.stop_convert;
498501
symbolt symbol=res.main_function;

src/java_bytecode/java_entry_point.h

-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ Author: Daniel Kroening, [email protected]
1919

2020
bool java_entry_point(
2121
class symbol_tablet &symbol_table,
22-
const irep_idt &main_class,
2322
class message_handlert &message_handler,
2423
bool assume_init_pointers_not_null,
2524
size_t max_nondet_array_length,
@@ -36,7 +35,6 @@ typedef struct
3635
/// Figures out the entry point of the code to verify
3736
main_function_resultt get_main_symbol(
3837
symbol_tablet &symbol_table,
39-
const irep_idt &main_class,
4038
message_handlert &,
4139
bool allow_no_body=false);
4240

0 commit comments

Comments
 (0)