-
Notifications
You must be signed in to change notification settings - Fork 273
Fixing inheritance issue for java programs. #1064
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:test-gen-support
from
Degiorgio:fix/inherited_methods
Jul 3, 2017
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
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,38 @@ | ||
default: tests.log | ||
|
||
test: | ||
@if ! ../test.pl -c ../../../src/cbmc/cbmc ; then \ | ||
../failed-tests-printer.pl ; \ | ||
exit 1 ; \ | ||
fi | ||
|
||
tests.log: ../test.pl | ||
@if ! ../test.pl -c ../../../src/cbmc/cbmc ; then \ | ||
../failed-tests-printer.pl ; \ | ||
exit 1 ; \ | ||
fi | ||
|
||
show: | ||
@for dir in *; do \ | ||
if [ -d "$$dir" ]; then \ | ||
vim -o "$$dir/*.java" "$$dir/*.out"; \ | ||
fi; \ | ||
done; | ||
|
||
clean: | ||
find -name '*.out' -execdir $(RM) '{}' \; | ||
find -name '*.gb' -execdir $(RM) '{}' \; | ||
$(RM) tests.log | ||
|
||
%.class: %.java ../../src/org.cprover.jar | ||
javac -g -cp ../../src/org.cprover.jar:. $< | ||
|
||
nondet_java_files := $(shell find . -name "Nondet*.java") | ||
nondet_class_files := $(patsubst %.java, %.class, $(nondet_java_files)) | ||
|
||
.PHONY: nondet-class-files | ||
nondet-class-files: $(nondet_class_files) | ||
|
||
.PHONY: clean-nondet-class-files | ||
clean-nondet-class-files: | ||
-rm $(nondet_class_files) |
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,5 @@ | ||
CORE | ||
test.class | ||
--function test.check | ||
^EXIT=0$ | ||
^SIGNAL=0$ |
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,20 @@ | ||
class A | ||
{ | ||
public int toInt() | ||
{ | ||
return 12345; | ||
} | ||
} | ||
|
||
class B extends A | ||
{ | ||
} | ||
|
||
class test | ||
{ | ||
void check() | ||
{ | ||
B b=new B(); | ||
assert(b.toInt()==12345); | ||
} | ||
} |
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,5 @@ | ||
CORE | ||
test.class | ||
--function test.check | ||
^EXIT=0$ | ||
^SIGNAL=0$ |
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,24 @@ | ||
class A | ||
{ | ||
protected int toInt() | ||
{ | ||
return 12345; | ||
} | ||
} | ||
|
||
class B extends A | ||
{ | ||
public void secondary() | ||
{ | ||
assert(toInt()==12345); | ||
} | ||
} | ||
|
||
class test | ||
{ | ||
void check() | ||
{ | ||
B b=new B(); | ||
b.secondary(); | ||
} | ||
} |
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,5 @@ | ||
CORE | ||
test.class | ||
--function test.check | ||
^EXIT=0$ | ||
^SIGNAL=0$ |
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,24 @@ | ||
class Z | ||
{ | ||
public int toInt() | ||
{ | ||
return 12345; | ||
} | ||
} | ||
|
||
class A extends Z | ||
{ | ||
} | ||
|
||
class B extends A | ||
{ | ||
} | ||
|
||
class test | ||
{ | ||
void check() | ||
{ | ||
B b=new B(); | ||
assert(b.toInt()==12345); | ||
} | ||
} |
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,5 @@ | ||
CORE | ||
test.class | ||
--function test.check | ||
^EXIT=0$ | ||
^SIGNAL=0$ |
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,28 @@ | ||
class A | ||
{ | ||
public int toInt() | ||
{ | ||
return 12345; | ||
} | ||
} | ||
|
||
class B extends A | ||
{ | ||
public int toInt() | ||
{ | ||
return 9999; | ||
} | ||
} | ||
|
||
class Z extends B | ||
{ | ||
} | ||
|
||
class test | ||
{ | ||
void check() | ||
{ | ||
Z z=new Z(); | ||
assert(z.toInt()==9999); | ||
} | ||
} |
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,5 @@ | ||
CORE | ||
test.class | ||
--function test.check | ||
^EXIT=0$ | ||
^SIGNAL=0$ |
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,21 @@ | ||
interface A | ||
{ | ||
public int toInt(); | ||
} | ||
|
||
class B implements A | ||
{ | ||
public int toInt() | ||
{ | ||
return 12345; | ||
} | ||
} | ||
|
||
class test | ||
{ | ||
void check() | ||
{ | ||
B b=new B(); | ||
assert(b.toInt()==12345); | ||
} | ||
} |
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,10 @@ | ||
package temp; | ||
|
||
class A | ||
{ | ||
int toint() | ||
{ | ||
return 123456; | ||
} | ||
} | ||
|
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,9 @@ | ||
package temp; | ||
|
||
public class B extends A | ||
{ | ||
public int check() | ||
{ | ||
return toint(); | ||
} | ||
} |
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,5 @@ | ||
CORE | ||
test.class | ||
--function test.check | ||
^EXIT=0$ | ||
^SIGNAL=0$ |
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 @@ | ||
import temp.B; | ||
|
||
public class test | ||
{ | ||
public void check() | ||
{ | ||
B myObject = new B(); | ||
assert(myObject.check()==123456); | ||
} | ||
} | ||
|
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 |
---|---|---|
|
@@ -19,11 +19,13 @@ Author: Daniel Kroening, [email protected] | |
#include <util/prefix.h> | ||
#include <util/arith_tools.h> | ||
#include <util/ieee_float.h> | ||
#include <util/invariant.h> | ||
|
||
#include <linking/zero_initializer.h> | ||
|
||
#include <goto-programs/cfg.h> | ||
#include <goto-programs/remove_exceptions.h> | ||
#include <goto-programs/class_hierarchy.h> | ||
#include <analyses/cfg_dominators.h> | ||
|
||
#include "java_bytecode_convert_method.h" | ||
|
@@ -32,6 +34,7 @@ Author: Daniel Kroening, [email protected] | |
#include "java_types.h" | ||
#include "java_utils.h" | ||
#include "java_string_library_preprocess.h" | ||
#include "java_utils.h" | ||
|
||
#include <limits> | ||
#include <algorithm> | ||
|
@@ -1428,12 +1431,12 @@ codet java_bytecode_convert_methodt::convert_instructions( | |
|
||
assert(arg0.id()==ID_virtual_function); | ||
|
||
// does the function symbol exist? | ||
// if we don't have a definition for the called symbol, and we won't | ||
// inherit a definition from a super-class, create a stub. | ||
irep_idt id=arg0.get(ID_identifier); | ||
|
||
if(symbol_table.symbols.find(id)==symbol_table.symbols.end()) | ||
if(symbol_table.symbols.find(id)==symbol_table.symbols.end() && | ||
!(is_virtual && is_method_inherited(arg0.get(ID_C_class), id))) | ||
{ | ||
// no, create stub | ||
symbolt symbol; | ||
symbol.name=id; | ||
symbol.base_name=arg0.get(ID_C_base_name); | ||
|
@@ -2687,3 +2690,40 @@ void java_bytecode_convert_method( | |
|
||
java_bytecode_convert_method(class_symbol, method); | ||
} | ||
|
||
const bool java_bytecode_convert_methodt::is_method_inherited( | ||
const irep_idt &classname, const irep_idt &methodid) const | ||
{ | ||
class_hierarchyt ch; | ||
namespacet ns(symbol_table); | ||
ch(symbol_table); | ||
|
||
std::string stripped_methodid(id2string(methodid)); | ||
stripped_methodid.erase(0, classname.size()); | ||
|
||
const std::string &classpackage=java_class_to_package(id2string(classname)); | ||
const auto &parents=ch.get_parents_trans(classname); | ||
for(const auto &parent : parents) | ||
{ | ||
const irep_idt id=id2string(parent)+stripped_methodid; | ||
const symbolt *symbol; | ||
if(!ns.lookup(id, symbol) && | ||
symbol->type.id()==ID_code) | ||
{ | ||
const auto &access=symbol->type.get(ID_access); | ||
if(access==ID_public || access==ID_protected) | ||
return true; | ||
// methods with the default access modifier are only | ||
// accessible within the same package. | ||
else if(access==ID_default && | ||
java_class_to_package(id2string(parent))==classpackage) | ||
return true; | ||
else if(access==ID_private) | ||
continue; | ||
else | ||
INVARIANT(false, "Unexpected access modifier."); | ||
} | ||
} | ||
return false; | ||
} | ||
|
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 |
---|---|---|
|
@@ -10,6 +10,7 @@ Author: Daniel Kroening, [email protected] | |
#include <util/prefix.h> | ||
#include <util/std_types.h> | ||
#include <util/invariant.h> | ||
#include <util/string_utils.h> | ||
|
||
#include "java_utils.h" | ||
#include "java_types.h" | ||
|
@@ -52,3 +53,8 @@ unsigned java_method_parameter_slots(const code_typet &t) | |
|
||
return slots; | ||
} | ||
|
||
const std::string java_class_to_package(const std::string &canonical_classname) | ||
{ | ||
return trim_from_last_delimiter(canonical_classname, '.'); | ||
} |
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
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.
Why not join the declaration with the assignment?
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.
Not sure, I follow, can you elaborate please?
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.
That was just a silly comment. Please disregard.