Skip to content

Commit

Permalink
Make return type of expr_instrumentation an optional
Browse files Browse the repository at this point in the history
  • Loading branch information
romainbrenguier committed Feb 21, 2018
1 parent 9c838a1 commit b0df38d
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions src/java_bytecode/java_bytecode_instrument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class java_bytecode_instrumentt:public messaget
void instrument_code(exprt &expr);
void add_expr_instrumentation(code_blockt &block, const exprt &expr);
void prepend_instrumentation(codet &code, code_blockt &instrumentation);
codet instrument_expr(const exprt &expr);
optionalt<codet> instrument_expr(const exprt &expr);
};

const std::vector<std::string> exception_needed_classes = { // NOLINT
Expand Down Expand Up @@ -328,13 +328,12 @@ void java_bytecode_instrumentt::add_expr_instrumentation(
code_blockt &block,
const exprt &expr)
{
codet expr_instrumentation=instrument_expr(expr);
if(expr_instrumentation!=code_skipt())
if(optionalt<codet> expr_instrumentation = instrument_expr(expr))
{
if(expr_instrumentation.get_statement()==ID_block)
block.append(to_code_block(expr_instrumentation));
if(expr_instrumentation->get_statement() == ID_block)
block.append(to_code_block(*expr_instrumentation));
else
block.move_to_operands(expr_instrumentation);
block.move_to_operands(*expr_instrumentation);
}
}

Expand Down Expand Up @@ -475,17 +474,15 @@ void java_bytecode_instrumentt::instrument_code(exprt &expr)
/// either assertions or runtime exceptions.
/// \param expr: the expression for which we compute
/// instrumentation
/// \return: The instrumentation required for `expr`
codet java_bytecode_instrumentt::instrument_expr(
const exprt &expr)
/// \return: The instrumentation for `expr` if required
optionalt<codet> java_bytecode_instrumentt::instrument_expr(const exprt &expr)
{
code_blockt result;
// First check our operands:
forall_operands(it, expr)
{
codet op_result=instrument_expr(*it);
if(op_result!=code_skipt())
result.move_to_operands(op_result);
if(optionalt<codet> op_result = instrument_expr(*it))
result.move_to_operands(*op_result);
}

// Add any check due at this node:
Expand Down Expand Up @@ -556,7 +553,7 @@ codet java_bytecode_instrumentt::instrument_expr(
}

if(result==code_blockt())
return code_skipt();
return {};
else
return result;
}
Expand Down

0 comments on commit b0df38d

Please sign in to comment.