@@ -325,9 +325,6 @@ main_function_resultt get_main_symbol(
325
325
message_handlert &message_handler,
326
326
bool allow_no_body)
327
327
{
328
- symbolt symbol;
329
- main_function_resultt res;
330
-
331
328
messaget message (message_handler);
332
329
333
330
// find main symbol
@@ -342,32 +339,26 @@ main_function_resultt get_main_symbol(
342
339
343
340
if (main_symbol_id==irep_idt ())
344
341
{
345
- message.error () << " main symbol resolution failed: "
346
- << error_message << messaget::eom;
347
- res.main_function =symbol;
348
- res.error_found =true ;
349
- res.stop_convert =true ;
350
- return res;
342
+ message.error ()
343
+ << " main symbol resolution failed: " << error_message << messaget::eom;
344
+ return main_function_resultt::Error;
351
345
}
352
346
353
- symbol_tablet::symbolst::const_iterator s_it =
354
- symbol_table.symbols . find (main_symbol_id);
347
+ symbol_tablet::opt_const_symbol_reft symbol =
348
+ symbol_table.lookup (main_symbol_id);
355
349
INVARIANT (
356
- s_it!=symbol_table. symbols . end () ,
350
+ symbol ,
357
351
" resolve_friendly_method_name should return a symbol-table identifier" );
358
352
359
- symbol=s_it->second ;
360
-
361
353
// check if it has a body
362
- if (symbol.value .is_nil () && !allow_no_body)
354
+ if (symbol-> get () .value .is_nil () && !allow_no_body)
363
355
{
364
- message.error () << " main method `" << main_class
365
- << " ' has no body" << messaget::eom;
366
- res.main_function =symbol;
367
- res.error_found =true ;
368
- res.stop_convert =true ;
369
- return res;
356
+ message.error ()
357
+ << " main method `" << main_class << " ' has no body" << messaget::eom;
358
+ return main_function_resultt::Error;
370
359
}
360
+
361
+ return main_function_resultt (*symbol); // Return found function
371
362
}
372
363
else
373
364
{
@@ -376,69 +367,49 @@ main_function_resultt get_main_symbol(
376
367
377
368
// are we given a main class?
378
369
if (main_class.empty ())
379
- {
380
- res.main_function =symbol;
381
- res.error_found =false ;
382
- res.stop_convert =true ;
383
- return res; // silently ignore
384
- }
370
+ return main_function_resultt::NotFound; // silently ignore
385
371
386
- std::string entry_method=
387
- id2string (main_class)+" .main" ;
372
+ std::string entry_method=id2string (main_class)+" .main" ;
388
373
389
374
std::string prefix=" java::" +entry_method+" :" ;
390
375
391
376
// look it up
392
- std::set<irep_idt > matches;
377
+ std::set<const symbolt * > matches;
393
378
394
- for (symbol_tablet::symbolst::const_iterator
395
- s_it=symbol_table.symbols .begin ();
396
- s_it!=symbol_table.symbols .end ();
397
- s_it++)
379
+ for (const auto &named_symbol : symbol_table.symbols )
398
380
{
399
- if (s_it->second .type .id ()==ID_code &&
400
- has_prefix (id2string (s_it->first ), prefix))
401
- matches.insert (s_it->first );
381
+ if (named_symbol.second .type .id ()==ID_code
382
+ && has_prefix (id2string (named_symbol.first ), prefix))
383
+ {
384
+ matches.insert (&named_symbol.second );
385
+ }
402
386
}
403
387
404
388
if (matches.empty ())
405
- {
406
389
// Not found, silently ignore
407
- res.main_function =symbol;
408
- res.error_found =false ;
409
- res.stop_convert =true ;
410
- return res;
411
- }
390
+ return main_function_resultt::NotFound;
412
391
413
- if (matches.size ()>= 2 )
392
+ if (matches.size ()>1 )
414
393
{
415
- message.error () << " main method in `" << main_class
416
- << " ' is ambiguous" << messaget::eom;
417
- res.main_function =symbolt ();
418
- res.error_found =true ;
419
- res.stop_convert =true ;
420
- return res; // give up with error, no main
394
+ message.error ()
395
+ << " main method in `" << main_class
396
+ << " ' is ambiguous" << messaget::eom;
397
+ return main_function_resultt::Error; // give up with error, no main
421
398
}
422
399
423
400
// function symbol
424
- symbol=symbol_table. symbols . find (* matches.begin ())-> second ;
401
+ const symbolt & symbol=** matches.begin ();
425
402
426
403
// check if it has a body
427
404
if (symbol.value .is_nil () && !allow_no_body)
428
405
{
429
- message.error () << " main method `" << main_class
430
- << " ' has no body" << messaget::eom;
431
- res.main_function =symbol;
432
- res.error_found =true ;
433
- res.stop_convert =true ;
434
- return res; // give up with error
406
+ message.error ()
407
+ << " main method `" << main_class << " ' has no body" << messaget::eom;
408
+ return main_function_resultt::Error; // give up with error
435
409
}
436
- }
437
410
438
- res.main_function =symbol;
439
- res.error_found =false ;
440
- res.stop_convert =false ;
441
- return res; // give up with error
411
+ return symbol; // Return found function
412
+ }
442
413
}
443
414
444
415
// / Given the \p symbol_table and the \p main_class to test, this function
@@ -491,8 +462,8 @@ bool java_entry_point(
491
462
messaget message (message_handler);
492
463
main_function_resultt res=
493
464
get_main_symbol (symbol_table, main_class, message_handler);
494
- if (res.stop_convert )
495
- return res. stop_convert ;
465
+ if (! res.is_success () )
466
+ return true ;
496
467
symbolt symbol=res.main_function ;
497
468
498
469
assert (!symbol.value .is_nil ());
0 commit comments