Skip to content

Commit

Permalink
Extract try_catch_handler function
Browse files Browse the repository at this point in the history
  • Loading branch information
romainbrenguier committed Jun 13, 2018
1 parent 87a4f31 commit 390063f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
31 changes: 19 additions & 12 deletions jbmc/src/java_bytecode/java_bytecode_convert_method.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1034,18 +1034,11 @@ codet java_bytecode_convert_methodt::convert_instructions(
i_it->statement=="invokespecial" ||
i_it->statement=="invokeinterface")
{
// find the corresponding try-catch blocks and add the handlers
// to the targets
for(const auto &exception_row : method.exception_table)
{
if(i_it->address>=exception_row.start_pc &&
i_it->address<exception_row.end_pc)
{
a_entry.first->second.successors.push_back(
exception_row.handler_pc);
targets.insert(exception_row.handler_pc);
}
}
const std::vector<unsigned int> handler =
try_catch_handler(i_it->address, method.exception_table);
std::list<unsigned int> &successors = a_entry.first->second.successors;
successors.insert(successors.end(), handler.begin(), handler.end());
targets.insert(handler.begin(), handler.end());
}

if(i_it->statement=="goto" ||
Expand Down Expand Up @@ -2726,6 +2719,20 @@ codet java_bytecode_convert_methodt::convert_instructions(
return code;
}

std::vector<unsigned> java_bytecode_convert_methodt::try_catch_handler(
const unsigned int address,
const java_bytecode_parse_treet::methodt::exception_tablet &exception_table)
const
{
std::vector<unsigned> result;
for(const auto &exception_row : exception_table)
{
if(address >= exception_row.start_pc && address < exception_row.end_pc)
result.push_back(exception_row.handler_pc);
}
return result;
}

/// This uses a cut-down version of the logic in
/// java_bytecode_convert_methodt::convert to initialize symbols for the
/// parameters and update the parameters in the type of method_symbol with
Expand Down
6 changes: 5 additions & 1 deletion jbmc/src/java_bytecode/java_bytecode_convert_method_class.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,10 @@ class java_bytecode_convert_methodt:public messaget
const typet &,
code_blockt &,
exprt &);
};

std::vector<unsigned int> try_catch_handler(
unsigned int address,
const java_bytecode_parse_treet::methodt::exception_tablet &exception_table)
const;

#endif

0 comments on commit 390063f

Please sign in to comment.