Skip to content

Move replace_java_nondet to java_bytecode #2097

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/ansi-c/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ various threading interfaces.

\section preprocessing Preprocessing & Parsing

In the \ref ansi-c and \ref java_bytecode directories
In the \ref ansi-c directory

**Key classes:**
* \ref languaget and its subclasses
Expand All @@ -46,7 +46,7 @@ digraph G {

\section type-checking Type-checking

In the \ref ansi-c and \ref java_bytecode directories.
In the \ref ansi-c directory

**Key classes:**
* \ref languaget and its subclasses
Expand Down
2 changes: 0 additions & 2 deletions src/cbmc/bmc.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ Author: Daniel Kroening, [email protected]
#include <util/options.h>
#include <util/ui_message.h>

#include <java_bytecode/java_enum_static_init_unwind_handler.h>

#include <solvers/prop/prop.h>
#include <solvers/prop/prop_conv.h>
#include <solvers/sat/cnf.h>
Expand Down
1 change: 0 additions & 1 deletion src/goto-programs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ SRC = basic_blocks.cpp \
remove_unused_functions.cpp \
remove_vector.cpp \
remove_virtual_functions.cpp \
replace_java_nondet.cpp \
generate_function_bodies.cpp \
resolve_inherited_component.cpp \
safety_checker.cpp \
Expand Down
1 change: 1 addition & 0 deletions src/java_bytecode/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ SRC = bytecode_info.cpp \
java_types.cpp \
java_utils.cpp \
mz_zip_archive.cpp \
replace_java_nondet.cpp \
remove_exceptions.cpp \
remove_instanceof.cpp \
select_pointer_type.cpp \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ Author: Reuben Thomas, [email protected]
/// \file
/// Replace Java Nondet expressions

#include "goto-programs/replace_java_nondet.h"
#include "goto-programs/goto_convert.h"
#include "goto-programs/goto_model.h"
#include "goto-programs/remove_skip.h"
#include "replace_java_nondet.h"

#include "util/irep_ids.h"
#include <goto-programs/goto_convert.h>
#include <goto-programs/goto_model.h>
#include <goto-programs/remove_skip.h>

#include <algorithm>
#include <regex>
Expand All @@ -24,23 +23,35 @@ Author: Reuben Thomas, [email protected]
class nondet_instruction_infot final
{
public:
enum class is_nondett:bool { FALSE, TRUE };
enum class is_nullablet:bool { FALSE, TRUE };
enum class is_nondett : bool
{
FALSE,
TRUE
};
enum class is_nullablet : bool
{
FALSE,
TRUE
};

nondet_instruction_infot():
is_nondet(is_nondett::FALSE),
is_nullable(is_nullablet::FALSE)
nondet_instruction_infot()
: is_nondet(is_nondett::FALSE), is_nullable(is_nullablet::FALSE)
{
}

explicit nondet_instruction_infot(is_nullablet is_nullable):
is_nondet(is_nondett::TRUE),
is_nullable(is_nullable)
explicit nondet_instruction_infot(is_nullablet is_nullable)
: is_nondet(is_nondett::TRUE), is_nullable(is_nullable)
{
}

is_nondett get_instruction_type() const { return is_nondet; }
is_nullablet get_nullable_type() const { return is_nullable; }
is_nondett get_instruction_type() const
{
return is_nondet;
}
is_nullablet get_nullable_type() const
{
return is_nullable;
}

private:
is_nondett is_nondet;
Expand All @@ -52,11 +63,11 @@ class nondet_instruction_infot final
/// \return A structure detailing whether the function call appears to be one of
/// our nondet library methods, and if so, whether or not it allows null
/// results.
static nondet_instruction_infot is_nondet_returning_object(
const code_function_callt &function_call)
static nondet_instruction_infot
is_nondet_returning_object(const code_function_callt &function_call)
{
const auto &function_symbol=to_symbol_expr(function_call.function());
const auto function_name=id2string(function_symbol.get_identifier());
const auto &function_symbol = to_symbol_expr(function_call.function());
const auto function_name = id2string(function_symbol.get_identifier());
const std::regex reg(
R"(.*org\.cprover\.CProver\.nondet)"
R"((?:Boolean|Byte|Char|Short|Int|Long|Float|Double|With(out)?Null.*))");
Expand All @@ -74,51 +85,51 @@ static nondet_instruction_infot is_nondet_returning_object(
/// recognised nondet library methods, and return some information about it.
/// \param instr: A goto-program instruction to check.
/// \return A structure detailing the properties of the nondet method.
static nondet_instruction_infot get_nondet_instruction_info(
const goto_programt::const_targett &instr)
static nondet_instruction_infot
get_nondet_instruction_info(const goto_programt::const_targett &instr)
{
if(!(instr->is_function_call() && instr->code.id()==ID_code))
if(!(instr->is_function_call() && instr->code.id() == ID_code))
{
return nondet_instruction_infot();
}
const auto &code=to_code(instr->code);
if(code.get_statement()!=ID_function_call)
const auto &code = to_code(instr->code);
if(code.get_statement() != ID_function_call)
{
return nondet_instruction_infot();
}
const auto &function_call=to_code_function_call(code);
const auto &function_call = to_code_function_call(code);
return is_nondet_returning_object(function_call);
}

/// Return whether the expression is a symbol with the specified identifier.
/// \param expr: The expression which may be a symbol.
/// \param identifier: Some identifier.
/// \return True if the expression is a symbol with the specified identifier.
static bool is_symbol_with_id(const exprt& expr, const irep_idt& identifier)
static bool is_symbol_with_id(const exprt &expr, const irep_idt &identifier)
{
return expr.id()==ID_symbol &&
to_symbol_expr(expr).get_identifier()==identifier;
return expr.id() == ID_symbol &&
to_symbol_expr(expr).get_identifier() == identifier;
}

/// Return whether the expression is a typecast with the specified identifier.
/// \param expr: The expression which may be a typecast.
/// \param identifier: Some identifier.
/// \return True if the expression is a typecast with one operand, and the
/// typecast's identifier matches the specified identifier.
static bool is_typecast_with_id(const exprt& expr, const irep_idt& identifier)
static bool is_typecast_with_id(const exprt &expr, const irep_idt &identifier)
{
if(!(expr.id()==ID_typecast && expr.operands().size()==1))
if(!(expr.id() == ID_typecast && expr.operands().size() == 1))
{
return false;
}
const auto &typecast=to_typecast_expr(expr);
if(!(typecast.op().id()==ID_symbol && !typecast.op().has_operands()))
const auto &typecast = to_typecast_expr(expr);
if(!(typecast.op().id() == ID_symbol && !typecast.op().has_operands()))
{
return false;
}
const auto &op_symbol=to_symbol_expr(typecast.op());
const auto &op_symbol = to_symbol_expr(typecast.op());
// Return whether the typecast has the expected operand
return op_symbol.get_identifier()==identifier;
return op_symbol.get_identifier() == identifier;
}

/// Return whether the instruction is an assignment, and the rhs is a symbol or
Expand All @@ -136,7 +147,7 @@ static bool is_assignment_from(
{
return false;
}
const auto &rhs=to_code_assign(instr.code).rhs();
const auto &rhs = to_code_assign(instr.code).rhs();
return is_symbol_with_id(rhs, identifier) ||
is_typecast_with_id(rhs, identifier);
}
Expand Down Expand Up @@ -165,10 +176,11 @@ static goto_programt::targett check_and_replace_target(
const goto_programt::targett &target)
{
// Check whether this is a nondet library method, and return if not
const auto instr_info=get_nondet_instruction_info(target);
const auto next_instr=std::next(target);
if(instr_info.get_instruction_type()==
nondet_instruction_infot::is_nondett::FALSE)
const auto instr_info = get_nondet_instruction_info(target);
const auto next_instr = std::next(target);
if(
instr_info.get_instruction_type() ==
nondet_instruction_infot::is_nondett::FALSE)
{
return next_instr;
}
Expand Down Expand Up @@ -227,8 +239,8 @@ static goto_programt::targett check_and_replace_target(

// Assume that the LHS of *this* assignment is the actual nondet variable
const auto &code_assign = to_code_assign(assignment_instruction->code);
const auto nondet_var=code_assign.lhs();
const auto source_loc=target->source_location;
const auto nondet_var = code_assign.lhs();
const auto source_loc = target->source_location;

// Erase from the nondet function call to the assignment
const auto after_matching_assignment = std::next(assignment_instruction);
Expand All @@ -239,20 +251,19 @@ static goto_programt::targett check_and_replace_target(
std::for_each(
target,
after_matching_assignment,
[](goto_programt::instructiont &instr)
{
[](goto_programt::instructiont &instr) { // NOLINT (*)
instr.make_skip();
});

const auto inserted=goto_program.insert_before(after_matching_assignment);
const auto inserted = goto_program.insert_before(after_matching_assignment);
inserted->make_assignment();
side_effect_expr_nondett inserted_expr(nondet_var.type());
inserted_expr.set_nullable(
instr_info.get_nullable_type()==
instr_info.get_nullable_type() ==
nondet_instruction_infot::is_nullablet::TRUE);
inserted->code=code_assignt(nondet_var, inserted_expr);
inserted->code.add_source_location()=source_loc;
inserted->source_location=source_loc;
inserted->code = code_assignt(nondet_var, inserted_expr);
inserted->code.add_source_location() = source_loc;
inserted->source_location = source_loc;

goto_program.update();

Expand All @@ -265,13 +276,12 @@ static goto_programt::targett check_and_replace_target(
/// \param goto_program: The goto program to modify.
static void replace_java_nondet(goto_programt &goto_program)
{
for(auto instruction_iterator=goto_program.instructions.begin(),
end=goto_program.instructions.end();
instruction_iterator!=end;)
for(auto instruction_iterator = goto_program.instructions.begin(),
end = goto_program.instructions.end();
instruction_iterator != end;)
{
instruction_iterator=check_and_replace_target(
goto_program,
instruction_iterator);
instruction_iterator =
check_and_replace_target(goto_program, instruction_iterator);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ Author: Reuben Thomas, [email protected]
/// \file
/// Replace Java Nondet expressions

#ifndef CPROVER_GOTO_PROGRAMS_REPLACE_JAVA_NONDET_H
#define CPROVER_GOTO_PROGRAMS_REPLACE_JAVA_NONDET_H
#ifndef CPROVER_JAVA_BYTECODE_REPLACE_JAVA_NONDET_H
#define CPROVER_JAVA_BYTECODE_REPLACE_JAVA_NONDET_H

class goto_modelt;
class goto_functionst;
Expand Down
2 changes: 1 addition & 1 deletion src/jbmc/jbmc_parse_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ Author: Daniel Kroening, [email protected]
#include <goto-programs/remove_asm.h>
#include <goto-programs/remove_unused_functions.h>
#include <goto-programs/remove_skip.h>
#include <goto-programs/replace_java_nondet.h>
#include <goto-programs/set_properties.h>
#include <goto-programs/show_goto_functions.h>
#include <goto-programs/show_symbol_table.h>
Expand All @@ -56,6 +55,7 @@ Author: Daniel Kroening, [email protected]
#include <java_bytecode/java_enum_static_init_unwind_handler.h>
#include <java_bytecode/remove_instanceof.h>
#include <java_bytecode/remove_exceptions.h>
#include <java_bytecode/replace_java_nondet.h>

#include <cbmc/version.h>

Expand Down
2 changes: 1 addition & 1 deletion unit/java_bytecode/java_replace_nondet/replace_nondet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
#include <goto-programs/goto_convert_functions.h>
#include <goto-programs/remove_virtual_functions.h>
#include <goto-programs/remove_returns.h>
#include <goto-programs/replace_java_nondet.h>

#include <java_bytecode/remove_instanceof.h>
#include <java_bytecode/replace_java_nondet.h>

#include <util/config.h>
#include <util/options.h>
Expand Down