-
Notifications
You must be signed in to change notification settings - Fork 273
Clean pr java front end #425
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
peterschrammel
merged 45 commits into
diffblue:master
from
mgudemann:clean_pr_java_front_end
Jan 26, 2017
Merged
Changes from all commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
15049b7
restructure expr2java
mgudemann a34def1
pre-load java.lang.Object / String in class queue
mgudemann 18b259b
correct array type for Java
mgudemann 66c760f
nondeterministic initialization
mgudemann 6c65dbe
exception table parser
mgudemann 58be145
handle java.lang.String literals
mgudemann 3bcca85
handle array length and runtime checks for Java
mgudemann ac295b2
Java assertion handling
mgudemann beec721
class conversion runtime checks / array handling
mgudemann 02caf23
java bytecode index in source location
mgudemann e629e13
Correct parsing / generation of source filename
mgudemann af23573
Clean up Java pointer cast handling
7fee670
extract java bytecode convert method class
mgudemann f0cb8ce
Java entry point / main function
c1a3493
Correct java type width handling
mgudemann dfe795a
pacify cpplint
mgudemann b651c4d
take comments into account
mgudemann 2b23e36
fix linter warnings after rebase
mgudemann 360ff4d
remove static method is_string_array
mgudemann 608c5e3
take comments into account
mgudemann 6d9a350
remove cast_if_necessary
mgudemann 67f4019
is_constructor and is_virtual as class methods
mgudemann ceea4b7
make param const reference in clean_deref
mgudemann 4bf1e4a
irep ID_java_super_method_call
mgudemann a358515
comments for java object factory
mgudemann f54bbc2
documentation block gen_nondeet_array_init
mgudemann 371f92f
remove default values from object factory
mgudemann b4ac05c
export as_number to java_utils.cpp
mgudemann b7cdfd3
take tautschnig's comments into account
mgudemann 344e4a3
remove namespace from vtable
mgudemann 8848f8f
remove const_cast
mgudemann 4b6c1ab
add java_utils.cpp
mgudemann f866a9f
Peter's comments
mgudemann e282703
remove superfluous std::move from conversion
mgudemann f36dcae
adapt NullPointer[1-4] regression tests
mgudemann 39fb017
default ctor for java_convert_methodt::variablet
mgudemann f5c89d0
take tautschnig's comments into account
mgudemann 39c3cf7
assert known Java object size
mgudemann 196dd5b
remove unused skip_initialize
mgudemann 31b25f7
remove TODOs from expr2java
mgudemann c1101ea
beautification
mgudemann 5e6f7ef
change "* "->" *", too
mgudemann 669a5b0
adapt NullPointer2 regression test
mgudemann eb71f2c
adapt interface in CEGIS with default values
mgudemann a0e251f
whitespace in front of {
mgudemann 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
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
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 |
---|---|---|
|
@@ -15,45 +15,12 @@ Author: Daniel Kroening, [email protected] | |
#include <util/arith_tools.h> | ||
|
||
#include <ansi-c/c_qualifiers.h> | ||
#include <ansi-c/c_misc.h> | ||
#include <ansi-c/expr2c_class.h> | ||
|
||
#include "java_types.h" | ||
#include "expr2java.h" | ||
|
||
class expr2javat:public expr2ct | ||
{ | ||
public: | ||
expr2javat(const namespacet &_ns):expr2ct(_ns) { } | ||
|
||
std::string convert(const exprt &src) override | ||
{ | ||
return expr2ct::convert(src); | ||
} | ||
|
||
std::string convert(const typet &src) override | ||
{ | ||
return expr2ct::convert(src); | ||
} | ||
|
||
protected: | ||
std::string convert(const exprt &src, unsigned &precedence) override; | ||
std::string convert_java_this(const exprt &src, unsigned precedence); | ||
std::string convert_java_instanceof(const exprt &src, unsigned precedence); | ||
std::string convert_java_new(const exprt &src, unsigned precedence); | ||
std::string convert_code_java_delete(const exprt &src, unsigned precedence); | ||
std::string convert_struct(const exprt &src, unsigned &precedence) override; | ||
std::string convert_code(const codet &src, unsigned indent) override; | ||
std::string convert_constant(const constant_exprt &src, unsigned &precedence) override; | ||
std::string convert_code_function_call(const code_function_callt &src, unsigned indent); | ||
|
||
std::string convert_rec( | ||
const typet &src, | ||
const c_qualifierst &qualifiers, | ||
const std::string &declarator) override; | ||
|
||
typedef std::unordered_set<std::string, string_hash> id_sett; | ||
}; | ||
|
||
/*******************************************************************\ | ||
|
||
Function: expr2javat::convert_code_function_call | ||
|
@@ -83,7 +50,6 @@ std::string expr2javat::convert_code_function_call( | |
unsigned p; | ||
std::string lhs_str=convert(src.lhs(), p); | ||
|
||
// TODO: ggf. Klammern je nach p | ||
dest+=lhs_str; | ||
dest+='='; | ||
} | ||
|
@@ -124,8 +90,10 @@ std::string expr2javat::convert_code_function_call( | |
unsigned p; | ||
std::string arg_str=convert(*it, p); | ||
|
||
if(first) first=false; else dest+=", "; | ||
// TODO: ggf. Klammern je nach p | ||
if(first) | ||
first=false; | ||
else | ||
dest+=", "; | ||
dest+=arg_str; | ||
} | ||
} | ||
|
@@ -244,15 +212,16 @@ std::string expr2javat::convert_constant( | |
else if(src.type()==java_char_type()) | ||
{ | ||
std::string dest; | ||
dest.reserve(10); | ||
dest.reserve(char_representation_length); | ||
|
||
mp_integer int_value; | ||
to_integer(src, int_value); | ||
if(!to_integer(src, int_value)) | ||
assert(false); | ||
|
||
dest+='\''; | ||
dest+="(char)'"; | ||
|
||
if(int_value>=' ' && int_value<127) | ||
dest+=(char)(int_value.to_long()); | ||
dest+=static_cast<char>(int_value.to_long()); | ||
else | ||
{ | ||
std::string hex=integer2string(int_value, 16); | ||
|
@@ -265,6 +234,26 @@ std::string expr2javat::convert_constant( | |
dest+='\''; | ||
return dest; | ||
} | ||
else if(src.type()==java_byte_type()) | ||
{ | ||
// No byte-literals in Java, so just cast: | ||
mp_integer int_value; | ||
if(!to_integer(src, int_value)) | ||
assert(false); | ||
std::string dest="(byte)"; | ||
dest+=integer2string(int_value); | ||
return dest; | ||
} | ||
else if(src.type()==java_short_type()) | ||
{ | ||
// No short-literals in Java, so just cast: | ||
mp_integer int_value; | ||
if(!to_integer(src, int_value)) | ||
assert(false); | ||
std::string dest="(short)"; | ||
dest+=integer2string(int_value); | ||
return dest; | ||
} | ||
else if(src.type()==java_long_type()) | ||
{ | ||
// long integer literals must have 'L' at the end | ||
|
@@ -319,7 +308,7 @@ std::string expr2javat::convert_rec( | |
else if(src==java_double_type()) | ||
return q+"double"+d; | ||
else if(src==java_boolean_type()) | ||
return q+"bool"+d; | ||
return q+"boolean"+d; | ||
else if(src==java_byte_type()) | ||
return q+"byte"+d; | ||
else if(src.id()==ID_code) | ||
|
@@ -348,7 +337,8 @@ std::string expr2javat::convert_rec( | |
|
||
if(code_type.has_ellipsis()) | ||
{ | ||
if(!parameters.empty()) dest+=", "; | ||
if(!parameters.empty()) | ||
dest+=", "; | ||
dest+="..."; | ||
} | ||
|
||
|
@@ -491,9 +481,10 @@ std::string expr2javat::convert( | |
const exprt &src, | ||
unsigned &precedence) | ||
{ | ||
const typet &type=ns.follow(src.type()); | ||
if(src.id()=="java-this") | ||
return convert_java_this(src, precedence=15); | ||
if(src.id()=="java_instanceof") | ||
if(src.id()==ID_java_instanceof) | ||
return convert_java_instanceof(src, precedence=15); | ||
else if(src.id()==ID_side_effect && | ||
(src.get(ID_statement)==ID_java_new || | ||
|
@@ -509,9 +500,22 @@ std::string expr2javat::convert( | |
else if(src.id()=="pod_constructor") | ||
return "pod_constructor"; | ||
else if(src.id()==ID_virtual_function) | ||
return convert_function(src, "VIRTUAL_FUNCTION", precedence=16); | ||
{ | ||
return "VIRTUAL_FUNCTION(" + | ||
id2string(src.get(ID_C_class)) + | ||
"." + | ||
id2string(src.get(ID_component_name)) + | ||
")"; | ||
} | ||
else if(src.id()==ID_java_string_literal) | ||
return '"'+id2string(src.get(ID_value))+'"'; // Todo: add escaping as needed | ||
return '"'+MetaString(src.get_string(ID_value))+'"'; | ||
else if(src.id()==ID_constant && (type.id()==ID_bool || type.id()==ID_c_bool)) | ||
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. Comment just for future improvement: we should factor out these "to_string" functions for each language, as currently similar code appears in multiple places in the code base. |
||
{ | ||
if(src.is_true()) | ||
return "true"; | ||
else | ||
return "false"; | ||
} | ||
else | ||
return expr2ct::convert(src, precedence); | ||
} | ||
|
@@ -536,7 +540,7 @@ std::string expr2javat::convert_code( | |
|
||
if(statement==ID_java_new || | ||
statement==ID_java_new_array) | ||
return convert_java_new(src,indent); | ||
return convert_java_new(src, indent); | ||
|
||
if(statement==ID_function_call) | ||
return convert_code_function_call(to_code_function_call(src), 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 |
---|---|---|
|
@@ -10,10 +10,51 @@ Author: Daniel Kroening, [email protected] | |
#define CPROVER_JAVA_BYTECODE_EXPR2JAVA_H | ||
|
||
#include <string> | ||
|
||
class exprt; | ||
class namespacet; | ||
class typet; | ||
#include <ansi-c/expr2c_class.h> | ||
|
||
class expr2javat:public expr2ct | ||
{ | ||
public: | ||
explicit expr2javat(const namespacet &_ns):expr2ct(_ns) { } | ||
|
||
virtual std::string convert(const exprt &src) | ||
{ | ||
return expr2ct::convert(src); | ||
} | ||
|
||
virtual std::string convert(const typet &src) | ||
{ | ||
return expr2ct::convert(src); | ||
} | ||
|
||
protected: | ||
virtual std::string convert(const exprt &src, unsigned &precedence); | ||
virtual std::string convert_java_this(const exprt &src, unsigned precedence); | ||
virtual std::string convert_java_instanceof( | ||
const exprt &src, | ||
unsigned precedence); | ||
virtual std::string convert_java_new(const exprt &src, unsigned precedence); | ||
virtual std::string convert_code_java_delete( | ||
const exprt &src, | ||
unsigned precedence); | ||
virtual std::string convert_struct(const exprt &src, unsigned &precedence); | ||
virtual std::string convert_code(const codet &src, unsigned indent); | ||
virtual std::string convert_constant( | ||
const constant_exprt &src, | ||
unsigned &precedence); | ||
virtual std::string convert_code_function_call( | ||
const code_function_callt &src, | ||
unsigned indent); | ||
|
||
virtual std::string convert_rec( | ||
const typet &src, | ||
const c_qualifierst &qualifiers, | ||
const std::string &declarator); | ||
|
||
// length of string representation of Java Char | ||
// representation is '\u0000' | ||
const std::size_t char_representation_length=8; | ||
}; | ||
|
||
std::string expr2java(const exprt &expr, const namespacet &ns); | ||
std::string type2java(const typet &type, const namespacet &ns); | ||
|
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.
Would anyone happen to know what "java-this" is good for?
git grep java-this
returns exactly this one code location. If no one knows, it should just go away.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.
git-blame points to this commit which introduced
java-this
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.
@kroening what's the rationale for "java-this" (I note that there also is "cpp-this")?
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.
Also unsure why we would need to distinguish the two. I'd defer a potential clean-up of this to a later PR.