-
Notifications
You must be signed in to change notification settings - Fork 277
Java object factory: retain tagged types #4161
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 3 commits into
diffblue:develop
from
smowton:smowton/fix/object-factory-keep-struct-tags
Feb 12, 2019
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 |
---|---|---|
|
@@ -249,9 +249,11 @@ void java_object_factoryt::gen_pointer_target_init( | |
PRECONDITION(expr.type().id() == ID_pointer); | ||
PRECONDITION(update_in_place != update_in_placet::MAY_UPDATE_IN_PLACE); | ||
|
||
if(target_type.id() == ID_struct) | ||
const typet &followed_target_type = ns.follow(target_type); | ||
|
||
if(followed_target_type.id() == ID_struct) | ||
{ | ||
const auto &target_class_type = to_java_class_type(target_type); | ||
const auto &target_class_type = to_java_class_type(followed_target_type); | ||
if(has_prefix(id2string(target_class_type.get_tag()), "java::array[")) | ||
{ | ||
gen_nondet_array_init( | ||
|
@@ -565,10 +567,11 @@ void java_object_factoryt::gen_nondet_pointer_init( | |
// When we visit for 2nd time a type AND the maximum depth is exceeded, we set | ||
// the pointer to NULL instead of recursively initializing the struct to which | ||
// it points. | ||
const typet &subtype=ns.follow(pointer_type.subtype()); | ||
if(subtype.id()==ID_struct) | ||
const typet &subtype = pointer_type.subtype(); | ||
const typet &followed_subtype = ns.follow(subtype); | ||
if(followed_subtype.id() == ID_struct) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🦅 |
||
{ | ||
const struct_typet &struct_type=to_struct_type(subtype); | ||
const struct_typet &struct_type = to_struct_type(followed_subtype); | ||
const irep_idt &struct_tag=struct_type.get_tag(); | ||
|
||
// If this is a recursive type of some kind AND the depth is exceeded, set | ||
|
@@ -604,7 +607,9 @@ void java_object_factoryt::gen_nondet_pointer_init( | |
// decide to do this for all types, we should do it here. | ||
// Note also that this logic is mirrored in | ||
// ci_lazy_methodst::initialize_instantiated_classes. | ||
if(const auto class_type = type_try_dynamic_cast<java_class_typet>(subtype)) | ||
if( | ||
const auto class_type = | ||
type_try_dynamic_cast<java_class_typet>(followed_subtype)) | ||
{ | ||
if(class_type->get_base("java::java.lang.Enum") && !must_be_null) | ||
{ | ||
|
@@ -1024,8 +1029,8 @@ void java_object_factoryt::gen_nondet_init( | |
update_in_placet update_in_place, | ||
const source_locationt &location) | ||
{ | ||
const typet &type = override_type.has_value() ? ns.follow(*override_type) | ||
: ns.follow(expr.type()); | ||
const typet &type = override_type.has_value() ? *override_type : expr.type(); | ||
const typet &followed_type = ns.follow(type); | ||
|
||
if(type.id()==ID_pointer) | ||
{ | ||
|
@@ -1049,9 +1054,9 @@ void java_object_factoryt::gen_nondet_init( | |
update_in_place, | ||
location); | ||
} | ||
else if(type.id()==ID_struct) | ||
else if(followed_type.id() == ID_struct) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🦅 |
||
{ | ||
const struct_typet struct_type=to_struct_type(type); | ||
const struct_typet struct_type = to_struct_type(followed_type); | ||
|
||
// If we are about to initialize a generic class (as a superclass object | ||
// for a different object), add its concrete types to the map and delete | ||
|
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
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
Binary file not shown.
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,11 @@ | ||
|
||
public class A { | ||
|
||
public B b; | ||
public C c; | ||
|
||
} | ||
|
||
class B { } | ||
|
||
class C { } |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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,8 @@ | ||
|
||
public class HasArray { | ||
|
||
public D[] ds; | ||
|
||
} | ||
|
||
class D { } |
Binary file not shown.
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,8 @@ | ||
|
||
public class HasEnum { | ||
|
||
public E e; | ||
|
||
} | ||
|
||
enum E { x, y, z } |
Binary file not shown.
16 changes: 16 additions & 0 deletions
16
jbmc/unit/java_bytecode/java_object_factory/HasGeneric.java
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,16 @@ | ||
|
||
public class HasGeneric { | ||
|
||
public Generic<String> s; | ||
public Generic<Integer> t; | ||
public OtherGeneric<String> u; | ||
|
||
} | ||
|
||
class Generic<T> { | ||
T t; | ||
} | ||
|
||
class OtherGeneric<T> { | ||
Generic<T> gen; | ||
} |
Binary file not shown.
Binary file not shown.
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,12 @@ | ||
|
||
public class Root { | ||
|
||
// This one isn't used in the tests; it just references other classes | ||
// to get them loaded. | ||
|
||
A a; | ||
HasArray ha; | ||
HasEnum he; | ||
HasGeneric hg; | ||
|
||
} |
1 change: 1 addition & 0 deletions
1
jbmc/unit/java_bytecode/java_object_factory/module_dependencies.txt
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
java_bytecode | ||
java_object_factory | ||
java-testing-utils | ||
langapi # should go away | ||
testing-utils | ||
util |
Oops, something went wrong.
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.
⛏️ Prefer not directly accessing the id:
🦅
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.
Has the advantage that if we choose to tag java_class_type to differentiate from other struct types, will automatically get checked here.
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.
I'll let the
id()
/dynamic_cast
war work itself out in the other thread before doing this on existing code :)