21
21
#include < util/namespace.h>
22
22
#include < util/pointer_offset_size.h>
23
23
#include < util/i2string.h>
24
+ #include < util/prefix.h>
24
25
25
26
#include < goto-programs/goto_functions.h>
26
27
@@ -366,10 +367,6 @@ bool java_entry_point(
366
367
symbol_table.symbols .end ())
367
368
return false ; // silently ignore
368
369
369
- #if 0
370
- std::cout << "Main: " << config.main << std::endl;
371
- #endif
372
-
373
370
messaget message (message_handler);
374
371
375
372
code_blockt struct_init_code; // struct init code if needed
@@ -381,15 +378,57 @@ bool java_entry_point(
381
378
// find main symbol
382
379
if (config.main !=" " )
383
380
{
384
- // look it up
385
- symbol_tablet::symbolst::const_iterator s_it
386
- =symbol_table.symbols .find (config.main );
381
+ // Add java:: prefix
382
+ std::string main_identifier=" java::" +config.main ;
383
+
384
+ symbol_tablet::symbolst::const_iterator s_it;
385
+
386
+ // Does it have a type signature? (':' suffix)
387
+ if (config.main .rfind (' :' )==std::string::npos)
388
+ {
389
+ std::string prefix=main_identifier+' :' ;
390
+ std::set<irep_idt> matches;
391
+
392
+ for (const auto & s : symbol_table.symbols )
393
+ if (has_prefix (id2string (s.first ), prefix) &&
394
+ s.second .type .id ()==ID_code)
395
+ matches.insert (s.first );
396
+
397
+ if (matches.empty ())
398
+ {
399
+ message.error () << " main symbol `" << config.main
400
+ << " ' not found" << messaget::eom;
401
+ return true ;
402
+ }
403
+ else if (matches.size ()==1 )
404
+ {
405
+ s_it=symbol_table.symbols .find (*matches.begin ());
406
+ assert (s_it!=symbol_table.symbols .end ());
407
+ }
408
+ else
409
+ {
410
+ message.error () << " main symbol `" << config.main
411
+ << " ' is ambiguous:\n " ;
387
412
388
- if (s_it==symbol_table.symbols .end ())
413
+ for (const auto & s : matches)
414
+ message.error () << " " << s << ' \n ' ;
415
+
416
+ message.error () << messaget::eom;
417
+
418
+ return true ;
419
+ }
420
+ }
421
+ else
389
422
{
390
- message.error () << " main symbol `" << config.main
391
- << " ' not found" << messaget::eom;
392
- return true ;
423
+ // just look it up
424
+ s_it=symbol_table.symbols .find (main_identifier);
425
+
426
+ if (s_it==symbol_table.symbols .end ())
427
+ {
428
+ message.error () << " main symbol `" << config.main
429
+ << " ' not found" << messaget::eom;
430
+ return true ;
431
+ }
393
432
}
394
433
395
434
// function symbol
@@ -411,13 +450,10 @@ bool java_entry_point(
411
450
}
412
451
413
452
// get name of associated struct
414
- size_t idx=config.main .rfind (" . " );
453
+ size_t idx=config.main .rfind (' . ' );
415
454
assert (idx!=std::string::npos);
416
455
assert (idx<config.main .size ());
417
456
std::string st=config.main .substr (0 , idx);
418
- #if 0
419
- std::cout << "Struct name: " << st << std::endl;
420
- #endif
421
457
422
458
// look it up
423
459
symbol_tablet::symbolst::const_iterator st_it
0 commit comments