Skip to content

Commit 3317a3a

Browse files
Tidied up code in get_main_symbol
1 parent 47fe36f commit 3317a3a

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed

src/java_bytecode/java_entry_point.cpp

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,6 @@ main_function_resultt get_main_symbol(
325325
message_handlert &message_handler,
326326
bool allow_no_body)
327327
{
328-
symbolt symbol;
329328
main_function_resultt res;
330329

331330
messaget message(message_handler);
@@ -344,28 +343,30 @@ main_function_resultt get_main_symbol(
344343
{
345344
message.error() << "main symbol resolution failed: "
346345
<< error_message << messaget::eom;
347-
res.main_function=symbol;
348346
res.status=main_function_resultt::Error;
349347
return res;
350348
}
351349

352-
symbol_tablet::symbolst::const_iterator s_it=
353-
symbol_table.symbols.find(main_symbol_id);
350+
symbol_tablet::opt_const_symbol_reft symbol=
351+
symbol_table.lookup(main_symbol_id);
354352
INVARIANT(
355-
s_it!=symbol_table.symbols.end(),
353+
symbol,
356354
"resolve_friendly_method_name should return a symbol-table identifier");
357355

358-
symbol=s_it->second;
359-
360356
// check if it has a body
361-
if(symbol.value.is_nil() && !allow_no_body)
357+
if(symbol->get().value.is_nil() && !allow_no_body)
362358
{
363359
message.error() << "main method `" << main_class
364360
<< "' has no body" << messaget::eom;
365-
res.main_function=symbol;
361+
res.main_function=*symbol;
366362
res.status=main_function_resultt::Error;
367363
return res;
368364
}
365+
366+
// Return found function
367+
res.main_function=*symbol;
368+
res.status=main_function_resultt::Success;
369+
return res;
369370
}
370371
else
371372
{
@@ -375,7 +376,6 @@ main_function_resultt get_main_symbol(
375376
// are we given a main class?
376377
if(main_class.empty())
377378
{
378-
res.main_function=symbol;
379379
res.status=main_function_resultt::NotFound;
380380
return res; // silently ignore
381381
}
@@ -386,7 +386,7 @@ main_function_resultt get_main_symbol(
386386
std::string prefix="java::"+entry_method+":";
387387

388388
// look it up
389-
std::set<irep_idt> matches;
389+
std::set<const symbolt *> matches;
390390

391391
for(symbol_tablet::symbolst::const_iterator
392392
s_it=symbol_table.symbols.begin();
@@ -395,18 +395,17 @@ main_function_resultt get_main_symbol(
395395
{
396396
if(s_it->second.type.id()==ID_code &&
397397
has_prefix(id2string(s_it->first), prefix))
398-
matches.insert(s_it->first);
398+
matches.insert(&s_it->second);
399399
}
400400

401401
if(matches.empty())
402402
{
403403
// Not found, silently ignore
404-
res.main_function=symbol;
405404
res.status=main_function_resultt::NotFound;
406405
return res;
407406
}
408407

409-
if(matches.size()>=2)
408+
if(matches.size()>1)
410409
{
411410
message.error() << "main method in `" << main_class
412411
<< "' is ambiguous" << messaget::eom;
@@ -416,7 +415,7 @@ main_function_resultt get_main_symbol(
416415
}
417416

418417
// function symbol
419-
symbol=symbol_table.symbols.find(*matches.begin())->second;
418+
const symbolt &symbol=**matches.begin();
420419

421420
// check if it has a body
422421
if(symbol.value.is_nil() && !allow_no_body)
@@ -427,12 +426,12 @@ main_function_resultt get_main_symbol(
427426
res.status=main_function_resultt::Error;
428427
return res; // give up with error
429428
}
430-
}
431429

432-
// Return found function
433-
res.main_function=symbol;
434-
res.status=main_function_resultt::Success;
435-
return res;
430+
// Return found function
431+
res.main_function=symbol;
432+
res.status=main_function_resultt::Success;
433+
return res;
434+
}
436435
}
437436

438437
/// Given the \p symbol_table and the \p main_class to test, this function

0 commit comments

Comments
 (0)