|
20 | 20 | #include <linking/zero_initializer.h>
|
21 | 21 |
|
22 | 22 | #include <goto-programs/cfg.h>
|
| 23 | +#include <goto-programs/remove_exceptions.h> |
23 | 24 | #include <analyses/cfg_dominators.h>
|
24 | 25 |
|
25 | 26 | #include "java_bytecode_convert_method.h"
|
@@ -1305,48 +1306,37 @@ codet java_bytecode_convert_methodt::convert_instructions(
|
1305 | 1306 | statement=std::string(id2string(statement), 0, statement.size()-2);
|
1306 | 1307 | }
|
1307 | 1308 |
|
1308 |
| - // we throw away the first statement in an exception handler |
1309 |
| - // as we don't know if a function call had a normal or exceptional return |
1310 | 1309 | auto it=method.exception_table.begin();
|
1311 | 1310 | for(; it!=method.exception_table.end(); ++it)
|
1312 | 1311 | {
|
1313 | 1312 | if(cur_pc==it->handler_pc)
|
1314 | 1313 | {
|
1315 |
| - exprt exc_var=variable( |
1316 |
| - arg0, statement[0], |
1317 |
| - i_it->address, |
1318 |
| - NO_CAST); |
1319 |
| - |
1320 |
| - // throw away the operands |
1321 |
| - pop_residue(bytecode_info.pop); |
1322 |
| - |
1323 |
| - // add a CATCH-PUSH signaling a handler |
1324 |
| - side_effect_expr_catcht catch_handler_expr; |
1325 |
| - // pack the exception variable so that it can be used |
1326 |
| - // later for instrumentation |
1327 |
| - catch_handler_expr.get_sub().resize(1); |
1328 |
| - catch_handler_expr.get_sub()[0]=exc_var; |
1329 |
| - |
1330 |
| - code_expressiont catch_handler(catch_handler_expr); |
1331 |
| - code_labelt newlabel(label(std::to_string(cur_pc)), |
1332 |
| - code_blockt()); |
1333 |
| - |
1334 |
| - code_blockt label_block=to_code_block(newlabel.code()); |
1335 |
| - code_blockt handler_block; |
1336 |
| - handler_block.move_to_operands(c); |
1337 |
| - handler_block.move_to_operands(catch_handler); |
1338 |
| - handler_block.move_to_operands(label_block); |
1339 |
| - c=handler_block; |
1340 |
| - break; |
| 1314 | + // at the beginning of a handler, clear the stack and |
| 1315 | + // push the corresponding exceptional return variable |
| 1316 | + stack.clear(); |
| 1317 | + auxiliary_symbolt new_symbol; |
| 1318 | + new_symbol.is_static_lifetime=true; |
| 1319 | + int file_name_length= |
| 1320 | + id2string(method.source_location.get_file()).size(); |
| 1321 | + // remove the file extension |
| 1322 | + const std::string &file_name= |
| 1323 | + id2string(method.source_location.get_file()). |
| 1324 | + substr(0, file_name_length-5); |
| 1325 | + // generate the name of the exceptional return variable |
| 1326 | + const std::string &exceptional_var_name= |
| 1327 | + "java::"+file_name+"."+ |
| 1328 | + id2string(method.name)+":"+ |
| 1329 | + id2string(method.signature)+ |
| 1330 | + EXC_SUFFIX; |
| 1331 | + new_symbol.base_name=exceptional_var_name; |
| 1332 | + new_symbol.name=exceptional_var_name; |
| 1333 | + new_symbol.type=typet(ID_pointer, empty_typet()); |
| 1334 | + new_symbol.mode=ID_java; |
| 1335 | + symbol_table.add(new_symbol); |
| 1336 | + stack.push_back(new_symbol.symbol_expr()); |
1341 | 1337 | }
|
1342 | 1338 | }
|
1343 | 1339 |
|
1344 |
| - if(it!=method.exception_table.end()) |
1345 |
| - { |
1346 |
| - // go straight to the next statement |
1347 |
| - continue; |
1348 |
| - } |
1349 |
| - |
1350 | 1340 | exprt::operandst op=pop(bytecode_info.pop);
|
1351 | 1341 | exprt::operandst results;
|
1352 | 1342 | results.resize(bytecode_info.push, nil_exprt());
|
@@ -2407,6 +2397,10 @@ codet java_bytecode_convert_methodt::convert_instructions(
|
2407 | 2397 | results[1]=op[0];
|
2408 | 2398 | results[0]=op[1];
|
2409 | 2399 | }
|
| 2400 | + else if(statement=="nop") |
| 2401 | + { |
| 2402 | + c=code_skipt(); |
| 2403 | + } |
2410 | 2404 | else
|
2411 | 2405 | {
|
2412 | 2406 | c=codet(statement);
|
@@ -2533,9 +2527,7 @@ codet java_bytecode_convert_methodt::convert_instructions(
|
2533 | 2527 | address_mapt::iterator a_it2=address_map.find(address);
|
2534 | 2528 | assert(a_it2!=address_map.end());
|
2535 | 2529 |
|
2536 |
| - // we don't worry about exception handlers as we don't load the |
2537 |
| - // operands from the stack anyway -- we keep explicit global |
2538 |
| - // exception variables |
| 2530 | + // clear the stack if this is an exception handler |
2539 | 2531 | for(const auto &exception_row : method.exception_table)
|
2540 | 2532 | {
|
2541 | 2533 | if(address==exception_row.handler_pc)
|
@@ -2604,7 +2596,6 @@ codet java_bytecode_convert_methodt::convert_instructions(
|
2604 | 2596 | c.copy_to_operands(*o_it);
|
2605 | 2597 | }
|
2606 | 2598 | }
|
2607 |
| - |
2608 | 2599 | a_it2->second.stack=stack;
|
2609 | 2600 | }
|
2610 | 2601 | }
|
|
0 commit comments