@@ -324,9 +324,6 @@ main_function_resultt get_main_symbol(
324324 message_handlert &message_handler,
325325 bool allow_no_body)
326326{
327- symbolt symbol;
328- main_function_resultt res;
329-
330327 messaget message (message_handler);
331328
332329 // find main symbol
@@ -341,32 +338,25 @@ main_function_resultt get_main_symbol(
341338
342339 if (main_symbol_id==irep_idt ())
343340 {
344- message.error () << " main symbol resolution failed: "
345- << error_message << messaget::eom;
346- res.main_function =symbol;
347- res.error_found =true ;
348- res.stop_convert =true ;
349- return res;
341+ message.error ()
342+ << " main symbol resolution failed: " << error_message << messaget::eom;
343+ return main_function_resultt::Error;
350344 }
351345
352- symbol_tablet::symbolst::const_iterator s_it=
353- symbol_table.symbols .find (main_symbol_id);
346+ const symbolt *symbol = symbol_table.lookup (main_symbol_id);
354347 INVARIANT (
355- s_it!=symbol_table. symbols . end () ,
348+ symbol != nullptr ,
356349 " resolve_friendly_method_name should return a symbol-table identifier" );
357350
358- symbol=s_it->second ;
359-
360351 // check if it has a body
361- if (symbol. value .is_nil () && !allow_no_body)
352+ if (symbol-> value .is_nil () && !allow_no_body)
362353 {
363- message.error () << " main method `" << main_class
364- << " ' has no body" << messaget::eom;
365- res.main_function =symbol;
366- res.error_found =true ;
367- res.stop_convert =true ;
368- return res;
354+ message.error ()
355+ << " main method `" << main_class << " ' has no body" << messaget::eom;
356+ return main_function_resultt::Error;
369357 }
358+
359+ return *symbol; // Return found function
370360 }
371361 else
372362 {
@@ -375,69 +365,49 @@ main_function_resultt get_main_symbol(
375365
376366 // are we given a main class?
377367 if (main_class.empty ())
378- {
379- res.main_function =symbol;
380- res.error_found =false ;
381- res.stop_convert =true ;
382- return res; // silently ignore
383- }
368+ return main_function_resultt::NotFound; // silently ignore
384369
385- std::string entry_method=
386- id2string (main_class)+" .main" ;
370+ std::string entry_method = id2string (main_class) + " .main" ;
387371
388372 std::string prefix=" java::" +entry_method+" :" ;
389373
390374 // look it up
391- std::set<irep_idt > matches;
375+ std::set<const symbolt * > matches;
392376
393- for (symbol_tablet::symbolst::const_iterator
394- s_it=symbol_table.symbols .begin ();
395- s_it!=symbol_table.symbols .end ();
396- s_it++)
377+ for (const auto &named_symbol : symbol_table.symbols )
397378 {
398- if (s_it->second .type .id ()==ID_code &&
399- has_prefix (id2string (s_it->first ), prefix))
400- matches.insert (s_it->first );
379+ if (named_symbol.second .type .id () == ID_code
380+ && has_prefix (id2string (named_symbol.first ), prefix))
381+ {
382+ matches.insert (&named_symbol.second );
383+ }
401384 }
402385
403386 if (matches.empty ())
404- {
405387 // Not found, silently ignore
406- res.main_function =symbol;
407- res.error_found =false ;
408- res.stop_convert =true ;
409- return res;
410- }
388+ return main_function_resultt::NotFound;
411389
412- if (matches.size ()>= 2 )
390+ if (matches.size () > 1 )
413391 {
414- message.error () << " main method in `" << main_class
415- << " ' is ambiguous" << messaget::eom;
416- res.main_function =symbolt ();
417- res.error_found =true ;
418- res.stop_convert =true ;
419- return res; // give up with error, no main
392+ message.error ()
393+ << " main method in `" << main_class
394+ << " ' is ambiguous" << messaget::eom;
395+ return main_function_resultt::Error; // give up with error, no main
420396 }
421397
422398 // function symbol
423- symbol=symbol_table. symbols . find (* matches.begin ())-> second ;
399+ const symbolt & symbol = ** matches.begin ();
424400
425401 // check if it has a body
426402 if (symbol.value .is_nil () && !allow_no_body)
427403 {
428- message.error () << " main method `" << main_class
429- << " ' has no body" << messaget::eom;
430- res.main_function =symbol;
431- res.error_found =true ;
432- res.stop_convert =true ;
433- return res; // give up with error
404+ message.error ()
405+ << " main method `" << main_class << " ' has no body" << messaget::eom;
406+ return main_function_resultt::Error; // give up with error
434407 }
435- }
436408
437- res.main_function =symbol;
438- res.error_found =false ;
439- res.stop_convert =false ;
440- return res; // give up with error
409+ return symbol; // Return found function
410+ }
441411}
442412
443413// / Given the \p symbol_table and the \p main_class to test, this function
@@ -490,8 +460,8 @@ bool java_entry_point(
490460 messaget message (message_handler);
491461 main_function_resultt res=
492462 get_main_symbol (symbol_table, main_class, message_handler);
493- if (res.stop_convert )
494- return res. stop_convert ;
463+ if (! res.is_success () )
464+ return true ;
495465 symbolt symbol=res.main_function ;
496466
497467 assert (!symbol.value .is_nil ());
0 commit comments