@@ -73,35 +73,6 @@ void create_initialize(symbol_tablet &symbol_table)
73
73
74
74
/* ******************************************************************\
75
75
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
-
105
76
Function: gen_nondet_init
106
77
107
78
Inputs:
@@ -287,6 +258,50 @@ symbolt &new_tmp_symbol(symbol_tablet &symbol_table)
287
258
288
259
/* ******************************************************************\
289
260
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
+
290
305
Function: java_static_lifetime_init
291
306
292
307
Inputs:
@@ -369,10 +384,6 @@ bool java_entry_point(
369
384
370
385
messaget message (message_handler);
371
386
372
- code_blockt object_init_code; // object initialization code if needed
373
- bool have_object=false ;
374
- symbol_exprt object_this_ptr;
375
-
376
387
symbolt symbol; // main function symbol
377
388
378
389
// find main symbol
@@ -440,44 +451,14 @@ bool java_entry_point(
440
451
<< " ' not a function" << messaget::eom;
441
452
return true ;
442
453
}
443
-
454
+
444
455
// check if it has a body
445
456
if (symbol.value .is_nil ())
446
457
{
447
458
message.error () << " main method `" << main_class
448
459
<< " ' has no body" << messaget::eom;
449
460
return true ;
450
461
}
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
- }
481
462
}
482
463
else
483
464
{
@@ -534,6 +515,8 @@ bool java_entry_point(
534
515
assert (!symbol.value .is_nil ());
535
516
assert (symbol.type .id ()==ID_code);
536
517
518
+ const code_typet &code_type=to_code_type (symbol.type );
519
+
537
520
create_initialize (symbol_table);
538
521
539
522
if (java_static_lifetime_init (symbol_table, symbol.location , message_handler))
@@ -561,35 +544,29 @@ bool java_entry_point(
561
544
init_code.move_to_operands (call_init);
562
545
}
563
546
564
- // add object initialization code
565
-
566
- if (have_object && !object_init_code.operands ().empty ())
567
- init_code.add (object_init_code);
568
-
569
547
// build call to the main method
570
548
571
549
code_function_callt call_main;
572
550
call_main.add_source_location ()=symbol.location ;
573
551
call_main.function ()=symbol.symbol_expr ();
574
552
575
553
const code_typet::parameterst ¶meters=
576
- to_code_type (symbol. type ) .parameters ();
554
+ code_type .parameters ();
577
555
578
556
exprt::operandst main_arguments;
579
557
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++ )
584
562
{
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);
588
568
}
589
569
590
- for (; i<parameters.size (); i++)
591
- main_arguments[i]=gen_argument (parameters[i].type ());
592
-
593
570
call_main.arguments ()=main_arguments;
594
571
595
572
init_code.move_to_operands (call_main);
0 commit comments