Skip to content

Commit a878070

Browse files
author
Daniel Kroening
committed
generated arguments can now be objects
1 parent aa9bfb7 commit a878070

File tree

2 files changed

+57
-80
lines changed

2 files changed

+57
-80
lines changed
-9 Bytes
Binary file not shown.

src/java_bytecode/java_entry_point.cpp

Lines changed: 57 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -73,35 +73,6 @@ void create_initialize(symbol_tablet &symbol_table)
7373

7474
/*******************************************************************\
7575
76-
Function: gen_argument
77-
78-
Inputs:
79-
80-
Outputs:
81-
82-
Purpose:
83-
84-
\*******************************************************************/
85-
86-
namespace {
87-
exprt gen_argument(const typet &type)
88-
{
89-
if(type.id()==ID_pointer)
90-
{
91-
/*
92-
side_effect_exprt result(ID_java_new);
93-
result.operands().resize(1);
94-
return result;
95-
*/
96-
return side_effect_expr_nondett(type);
97-
}
98-
else
99-
return side_effect_expr_nondett(type);
100-
}
101-
}
102-
103-
/*******************************************************************\
104-
10576
Function: gen_nondet_init
10677
10778
Inputs:
@@ -287,6 +258,50 @@ symbolt &new_tmp_symbol(symbol_tablet &symbol_table)
287258

288259
/*******************************************************************\
289260
261+
Function: gen_argument
262+
263+
Inputs:
264+
265+
Outputs:
266+
267+
Purpose:
268+
269+
\*******************************************************************/
270+
271+
namespace {
272+
exprt gen_argument(
273+
const typet &type,
274+
code_blockt &init_code,
275+
bool is_this,
276+
symbol_tablet &symbol_table)
277+
{
278+
if(type.id()==ID_pointer)
279+
{
280+
symbolt &aux_symbol=new_tmp_symbol(symbol_table);
281+
aux_symbol.type=type;
282+
aux_symbol.is_static_lifetime=true;
283+
284+
exprt object_this_ptr=aux_symbol.symbol_expr();
285+
286+
const namespacet ns(symbol_table);
287+
gen_nondet_init(object_this_ptr, init_code, ns);
288+
289+
return side_effect_expr_nondett(type);
290+
}
291+
else if(type.id()==ID_c_bool)
292+
{
293+
// We force this to 0 and 1 and won't consider
294+
// other values.
295+
//return typecast_exprt(side_effect_expr_nondett(bool_typet()), type);
296+
return typecast_exprt(false_exprt(), type);
297+
}
298+
else
299+
return side_effect_expr_nondett(type);
300+
}
301+
}
302+
303+
/*******************************************************************\
304+
290305
Function: java_static_lifetime_init
291306
292307
Inputs:
@@ -369,10 +384,6 @@ bool java_entry_point(
369384

370385
messaget message(message_handler);
371386

372-
code_blockt object_init_code; // object initialization code if needed
373-
bool have_object=false;
374-
symbol_exprt object_this_ptr;
375-
376387
symbolt symbol; // main function symbol
377388

378389
// find main symbol
@@ -440,44 +451,14 @@ bool java_entry_point(
440451
<< "' not a function" << messaget::eom;
441452
return true;
442453
}
443-
454+
444455
// check if it has a body
445456
if(symbol.value.is_nil())
446457
{
447458
message.error() << "main method `" << main_class
448459
<< "' has no body" << messaget::eom;
449460
return true;
450461
}
451-
452-
// get name of associated class
453-
size_t idx=config.main.rfind('.');
454-
assert(idx!=std::string::npos);
455-
assert(idx<config.main.size());
456-
std::string class_name=config.main.substr(0, idx);
457-
458-
// look it up
459-
symbol_tablet::symbolst::const_iterator st_it=
460-
symbol_table.symbols.find(class_name);
461-
462-
if(st_it!=symbol_table.symbols.end() &&
463-
st_it->second.type.id()==ID_struct)
464-
{
465-
const symbolt &struct_symbol=st_it->second;
466-
assert(struct_symbol.type.id()==ID_struct);
467-
const struct_typet &struct_type=to_struct_type(struct_symbol.type);
468-
const pointer_typet pointer_type(struct_type);
469-
470-
symbolt &aux_symbol=new_tmp_symbol(symbol_table);
471-
aux_symbol.type=pointer_type;
472-
aux_symbol.is_static_lifetime=true;
473-
474-
object_this_ptr=aux_symbol.symbol_expr();
475-
476-
namespacet ns(symbol_table);
477-
gen_nondet_init(object_this_ptr, object_init_code, ns);
478-
479-
have_object=true;
480-
}
481462
}
482463
else
483464
{
@@ -534,6 +515,8 @@ bool java_entry_point(
534515
assert(!symbol.value.is_nil());
535516
assert(symbol.type.id()==ID_code);
536517

518+
const code_typet &code_type=to_code_type(symbol.type);
519+
537520
create_initialize(symbol_table);
538521

539522
if(java_static_lifetime_init(symbol_table, symbol.location, message_handler))
@@ -561,35 +544,29 @@ bool java_entry_point(
561544
init_code.move_to_operands(call_init);
562545
}
563546

564-
// add object initialization code
565-
566-
if(have_object && !object_init_code.operands().empty())
567-
init_code.add(object_init_code);
568-
569547
// build call to the main method
570548

571549
code_function_callt call_main;
572550
call_main.add_source_location()=symbol.location;
573551
call_main.function()=symbol.symbol_expr();
574552

575553
const code_typet::parameterst &parameters=
576-
to_code_type(symbol.type).parameters();
554+
code_type.parameters();
577555

578556
exprt::operandst main_arguments;
579557
main_arguments.resize(parameters.size());
580-
581-
unsigned i=0;
582-
583-
if(have_object)
558+
559+
for(std::size_t param_number=0;
560+
param_number<parameters.size();
561+
param_number++)
584562
{
585-
assert(parameters.size()>=1);
586-
main_arguments[0]=object_this_ptr;
587-
i++;
563+
bool is_this=param_number==0 &&
564+
parameters[param_number].get_bool(ID_C_this);
565+
main_arguments[param_number]=
566+
gen_argument(parameters[param_number].type(),
567+
init_code, is_this, symbol_table);
588568
}
589569

590-
for(; i<parameters.size(); i++)
591-
main_arguments[i]=gen_argument(parameters[i].type());
592-
593570
call_main.arguments()=main_arguments;
594571

595572
init_code.move_to_operands(call_main);

0 commit comments

Comments
 (0)