Skip to content

Commit 390063f

Browse files
Extract try_catch_handler function
1 parent 87a4f31 commit 390063f

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

jbmc/src/java_bytecode/java_bytecode_convert_method.cpp

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,18 +1034,11 @@ codet java_bytecode_convert_methodt::convert_instructions(
10341034
i_it->statement=="invokespecial" ||
10351035
i_it->statement=="invokeinterface")
10361036
{
1037-
// find the corresponding try-catch blocks and add the handlers
1038-
// to the targets
1039-
for(const auto &exception_row : method.exception_table)
1040-
{
1041-
if(i_it->address>=exception_row.start_pc &&
1042-
i_it->address<exception_row.end_pc)
1043-
{
1044-
a_entry.first->second.successors.push_back(
1045-
exception_row.handler_pc);
1046-
targets.insert(exception_row.handler_pc);
1047-
}
1048-
}
1037+
const std::vector<unsigned int> handler =
1038+
try_catch_handler(i_it->address, method.exception_table);
1039+
std::list<unsigned int> &successors = a_entry.first->second.successors;
1040+
successors.insert(successors.end(), handler.begin(), handler.end());
1041+
targets.insert(handler.begin(), handler.end());
10491042
}
10501043

10511044
if(i_it->statement=="goto" ||
@@ -2726,6 +2719,20 @@ codet java_bytecode_convert_methodt::convert_instructions(
27262719
return code;
27272720
}
27282721

2722+
std::vector<unsigned> java_bytecode_convert_methodt::try_catch_handler(
2723+
const unsigned int address,
2724+
const java_bytecode_parse_treet::methodt::exception_tablet &exception_table)
2725+
const
2726+
{
2727+
std::vector<unsigned> result;
2728+
for(const auto &exception_row : exception_table)
2729+
{
2730+
if(address >= exception_row.start_pc && address < exception_row.end_pc)
2731+
result.push_back(exception_row.handler_pc);
2732+
}
2733+
return result;
2734+
}
2735+
27292736
/// This uses a cut-down version of the logic in
27302737
/// java_bytecode_convert_methodt::convert to initialize symbols for the
27312738
/// parameters and update the parameters in the type of method_symbol with

jbmc/src/java_bytecode/java_bytecode_convert_method_class.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,10 @@ class java_bytecode_convert_methodt:public messaget
273273
const typet &,
274274
code_blockt &,
275275
exprt &);
276-
};
276+
277+
std::vector<unsigned int> try_catch_handler(
278+
unsigned int address,
279+
const java_bytecode_parse_treet::methodt::exception_tablet &exception_table)
280+
const;
277281

278282
#endif

0 commit comments

Comments
 (0)