Skip to content

Commit 5b67c01

Browse files
author
Daniel Kroening
committed
methods can now be specified without java:: prefix and without type suffix, if unambiguous
1 parent 1fcc4ea commit 5b67c01

File tree

4 files changed

+54
-18
lines changed

4 files changed

+54
-18
lines changed

regression/cbmc-java/function1/test.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CORE
22
Main.class
3-
--function "java::Other.fail:()V"
3+
--function "Other.fail:()V"
44
^EXIT=10$
55
^SIGNAL=0$
66
^VERIFICATION FAILED$

regression/cbmc-java/function2/test.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CORE
22
Main.class
3-
--function "java::D.fail:()V"
3+
--function "D.fail:()V"
44
^EXIT=10$
55
^SIGNAL=0$
66
^VERIFICATION FAILED$

regression/cbmc-java/function3/test.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CORE
22
Main.class
3-
--function "java::A.dummy:()V"
3+
--function "A.dummy:()V"
44
^EXIT=0$
55
^SIGNAL=0$
66
^VERIFICATION SUCCESSFUL$

src/java_bytecode/java_entry_point.cpp

+51-15
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Author: Daniel Kroening, [email protected]
2121
#include <util/namespace.h>
2222
#include <util/pointer_offset_size.h>
2323
#include <util/i2string.h>
24+
#include <util/prefix.h>
2425

2526
#include <goto-programs/goto_functions.h>
2627

@@ -366,10 +367,6 @@ bool java_entry_point(
366367
symbol_table.symbols.end())
367368
return false; // silently ignore
368369

369-
#if 0
370-
std::cout << "Main: " << config.main << std::endl;
371-
#endif
372-
373370
messaget message(message_handler);
374371

375372
code_blockt struct_init_code; // struct init code if needed
@@ -381,15 +378,57 @@ bool java_entry_point(
381378
// find main symbol
382379
if(config.main!="")
383380
{
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";
387412

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
389422
{
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+
}
393432
}
394433

395434
// function symbol
@@ -411,13 +450,10 @@ bool java_entry_point(
411450
}
412451

413452
// get name of associated struct
414-
size_t idx=config.main.rfind(".");
453+
size_t idx=config.main.rfind('.');
415454
assert(idx!=std::string::npos);
416455
assert(idx<config.main.size());
417456
std::string st=config.main.substr(0, idx);
418-
#if 0
419-
std::cout << "Struct name: " << st << std::endl;
420-
#endif
421457

422458
// look it up
423459
symbol_tablet::symbolst::const_iterator st_it

0 commit comments

Comments
 (0)