-
Notifications
You must be signed in to change notification settings - Fork 274
Add java_instanceof_exprt, and use it in place of raw exprts #5039
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
smowton
merged 1 commit into
diffblue:develop
from
smowton:smowton/cleanup/java-instanceof-expr
Aug 20, 2019
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ Author: Daniel Kroening, [email protected] | |
#include <ansi-c/c_misc.h> | ||
#include <ansi-c/expr2c_class.h> | ||
|
||
#include "java_expr.h" | ||
#include "java_qualifiers.h" | ||
#include "java_string_literal_expr.h" | ||
#include "java_types.h" | ||
|
@@ -320,16 +321,10 @@ std::string expr2javat::convert_java_this() | |
|
||
std::string expr2javat::convert_java_instanceof(const exprt &src) | ||
{ | ||
if(src.operands().size()!=2) | ||
{ | ||
unsigned precedence; | ||
return convert_norep(src, precedence); | ||
} | ||
|
||
const auto &binary_expr = to_binary_expr(src); | ||
const auto &instanceof_expr = to_java_instanceof_expr(src); | ||
|
||
return convert(binary_expr.op0()) + " instanceof " + | ||
convert(binary_expr.op1().type()); | ||
return convert(instanceof_expr.tested_expr()) + " instanceof " + | ||
convert(instanceof_expr.target_type()); | ||
} | ||
|
||
std::string expr2javat::convert_code_java_new(const exprt &src, unsigned indent) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ Author: Daniel Kroening, [email protected] | |
#include "bytecode_info.h" | ||
#include "java_bytecode_convert_method.h" | ||
#include "java_bytecode_convert_method_class.h" | ||
#include "java_expr.h" | ||
#include "java_static_initializers.h" | ||
#include "java_string_library_preprocess.h" | ||
#include "java_string_literal_expr.h" | ||
|
@@ -1687,8 +1688,8 @@ java_bytecode_convert_methodt::convert_instructions(const methodt &method) | |
{ | ||
PRECONDITION(op.size() == 1 && results.size() == 1); | ||
|
||
results[0]= | ||
binary_predicate_exprt(op[0], ID_java_instanceof, arg0); | ||
results[0] = | ||
java_instanceof_exprt(op[0], to_struct_tag_type(arg0.type())); | ||
} | ||
else if(bytecode == BC_monitorenter || bytecode == BC_monitorexit) | ||
{ | ||
|
@@ -2326,7 +2327,7 @@ void java_bytecode_convert_methodt::convert_checkcast( | |
codet &c, | ||
exprt::operandst &results) const | ||
{ | ||
binary_predicate_exprt check(op[0], ID_java_instanceof, arg0); | ||
java_instanceof_exprt check(op[0], to_struct_tag_type(arg0.type())); | ||
code_assertt assert_class(check); | ||
assert_class.add_source_location().set_comment("Dynamic cast check"); | ||
assert_class.add_source_location().set_property_class("bad-dynamic-cast"); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/*******************************************************************\ | ||
|
||
Module: Java-specific exprt subclasses | ||
|
||
Author: Diffblue Ltd | ||
|
||
\*******************************************************************/ | ||
|
||
/// \file | ||
/// Java-specific exprt subclasses | ||
|
||
#ifndef CPROVER_JAVA_BYTECODE_JAVA_EXPR_H | ||
#define CPROVER_JAVA_BYTECODE_JAVA_EXPR_H | ||
|
||
#include <util/std_expr.h> | ||
|
||
class java_instanceof_exprt : public binary_predicate_exprt | ||
{ | ||
public: | ||
java_instanceof_exprt(exprt lhs, const struct_tag_typet &target_type) | ||
: binary_predicate_exprt( | ||
std::move(lhs), | ||
ID_java_instanceof, | ||
type_exprt(target_type)) | ||
{ | ||
} | ||
|
||
const exprt &tested_expr() const | ||
{ | ||
return op0(); | ||
} | ||
exprt &tested_expr() | ||
{ | ||
return op0(); | ||
} | ||
|
||
const struct_tag_typet &target_type() const | ||
{ | ||
return to_struct_tag_type(op1().type()); | ||
} | ||
|
||
static void check( | ||
const exprt &expr, | ||
const validation_modet vm = validation_modet::INVARIANT) | ||
{ | ||
binary_predicate_exprt::check(expr, vm); | ||
} | ||
|
||
static void validate( | ||
const exprt &expr, | ||
const namespacet &ns, | ||
const validation_modet vm = validation_modet::INVARIANT) | ||
{ | ||
binary_predicate_exprt::validate(expr, ns, vm); | ||
|
||
DATA_CHECK( | ||
vm, | ||
can_cast_expr<type_exprt>(expr.op1()), | ||
"java_instanceof_exprt rhs should be a type_exprt"); | ||
DATA_CHECK( | ||
vm, | ||
can_cast_type<struct_tag_typet>(expr.op1().type()), | ||
"java_instanceof_exprt rhs should denote a struct_tag_typet"); | ||
} | ||
}; | ||
|
||
template <> | ||
inline bool can_cast_expr<java_instanceof_exprt>(const exprt &base) | ||
{ | ||
return can_cast_expr<binary_exprt>(base) && base.id() == ID_java_instanceof; | ||
} | ||
|
||
inline void validate_expr(const java_instanceof_exprt &value) | ||
{ | ||
java_instanceof_exprt::check(value); | ||
} | ||
|
||
/// \brief Cast an exprt to a \ref java_instanceof_exprt | ||
/// | ||
/// \a expr must be known to be \ref java_instanceof_exprt. | ||
/// | ||
/// \param expr: Source expression | ||
/// \return Object of type \ref java_instanceof_exprt | ||
inline const java_instanceof_exprt &to_java_instanceof_expr(const exprt &expr) | ||
{ | ||
java_instanceof_exprt::check(expr); | ||
PRECONDITION(can_cast_expr<java_instanceof_exprt>(expr)); | ||
return static_cast<const java_instanceof_exprt &>(expr); | ||
} | ||
|
||
/// \copydoc to_java_instanceof_expr(const exprt &) | ||
inline java_instanceof_exprt &to_java_instanceof_expr(exprt &expr) | ||
{ | ||
java_instanceof_exprt::check(expr); | ||
PRECONDITION(can_cast_expr<java_instanceof_exprt>(expr)); | ||
return static_cast<java_instanceof_exprt &>(expr); | ||
} | ||
|
||
#endif // CPROVER_JAVA_BYTECODE_JAVA_EXPR_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Surprising that clang-format doesn't complain...