@@ -324,9 +324,6 @@ main_function_resultt get_main_symbol(
324
324
message_handlert &message_handler,
325
325
bool allow_no_body)
326
326
{
327
- symbolt symbol;
328
- main_function_resultt res;
329
-
330
327
messaget message (message_handler);
331
328
332
329
// find main symbol
@@ -341,32 +338,25 @@ main_function_resultt get_main_symbol(
341
338
342
339
if (main_symbol_id==irep_idt ())
343
340
{
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;
350
344
}
351
345
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);
354
347
INVARIANT (
355
- s_it!=symbol_table. symbols . end () ,
348
+ symbol != nullptr ,
356
349
" resolve_friendly_method_name should return a symbol-table identifier" );
357
350
358
- symbol=s_it->second ;
359
-
360
351
// check if it has a body
361
- if (symbol. value .is_nil () && !allow_no_body)
352
+ if (symbol-> value .is_nil () && !allow_no_body)
362
353
{
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;
369
357
}
358
+
359
+ return *symbol; // Return found function
370
360
}
371
361
else
372
362
{
@@ -375,69 +365,49 @@ main_function_resultt get_main_symbol(
375
365
376
366
// are we given a main class?
377
367
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
384
369
385
- std::string entry_method=
386
- id2string (main_class)+" .main" ;
370
+ std::string entry_method = id2string (main_class) + " .main" ;
387
371
388
372
std::string prefix=" java::" +entry_method+" :" ;
389
373
390
374
// look it up
391
- std::set<irep_idt > matches;
375
+ std::set<const symbolt * > matches;
392
376
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 )
397
378
{
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
+ }
401
384
}
402
385
403
386
if (matches.empty ())
404
- {
405
387
// 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;
411
389
412
- if (matches.size ()>= 2 )
390
+ if (matches.size () > 1 )
413
391
{
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
420
396
}
421
397
422
398
// function symbol
423
- symbol=symbol_table. symbols . find (* matches.begin ())-> second ;
399
+ const symbolt & symbol = ** matches.begin ();
424
400
425
401
// check if it has a body
426
402
if (symbol.value .is_nil () && !allow_no_body)
427
403
{
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
434
407
}
435
- }
436
408
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
+ }
441
411
}
442
412
443
413
// / Given the \p symbol_table and the \p main_class to test, this function
@@ -490,8 +460,8 @@ bool java_entry_point(
490
460
messaget message (message_handler);
491
461
main_function_resultt res=
492
462
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 ;
495
465
symbolt symbol=res.main_function ;
496
466
497
467
assert (!symbol.value .is_nil ());
0 commit comments