Skip to content

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
merged 45 commits into from
Jan 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
15049b7
restructure expr2java
mgudemann Nov 3, 2016
a34def1
pre-load java.lang.Object / String in class queue
mgudemann Nov 4, 2016
18b259b
correct array type for Java
mgudemann Nov 3, 2016
66c760f
nondeterministic initialization
mgudemann Dec 6, 2016
6c65dbe
exception table parser
mgudemann Nov 4, 2016
58be145
handle java.lang.String literals
mgudemann Nov 4, 2016
3bcca85
handle array length and runtime checks for Java
mgudemann Nov 4, 2016
ac295b2
Java assertion handling
mgudemann Nov 4, 2016
beec721
class conversion runtime checks / array handling
mgudemann Nov 4, 2016
02caf23
java bytecode index in source location
mgudemann Nov 4, 2016
e629e13
Correct parsing / generation of source filename
mgudemann Nov 4, 2016
af23573
Clean up Java pointer cast handling
Jan 11, 2017
7fee670
extract java bytecode convert method class
mgudemann Nov 11, 2016
f0cb8ce
Java entry point / main function
Jan 11, 2017
c1a3493
Correct java type width handling
mgudemann Dec 19, 2016
dfe795a
pacify cpplint
mgudemann Jan 13, 2017
b651c4d
take comments into account
mgudemann Jan 13, 2017
2b23e36
fix linter warnings after rebase
mgudemann Jan 15, 2017
360ff4d
remove static method is_string_array
mgudemann Jan 15, 2017
608c5e3
take comments into account
mgudemann Jan 15, 2017
6d9a350
remove cast_if_necessary
mgudemann Jan 20, 2017
67f4019
is_constructor and is_virtual as class methods
mgudemann Jan 20, 2017
ceea4b7
make param const reference in clean_deref
mgudemann Jan 15, 2017
4bf1e4a
irep ID_java_super_method_call
mgudemann Jan 15, 2017
a358515
comments for java object factory
mgudemann Jan 15, 2017
f54bbc2
documentation block gen_nondeet_array_init
mgudemann Jan 15, 2017
371f92f
remove default values from object factory
mgudemann Jan 15, 2017
b4ac05c
export as_number to java_utils.cpp
mgudemann Jan 17, 2017
b7cdfd3
take tautschnig's comments into account
mgudemann Jan 20, 2017
344e4a3
remove namespace from vtable
mgudemann Jan 23, 2017
8848f8f
remove const_cast
mgudemann Jan 23, 2017
4b6c1ab
add java_utils.cpp
mgudemann Jan 23, 2017
f866a9f
Peter's comments
mgudemann Jan 23, 2017
e282703
remove superfluous std::move from conversion
mgudemann Jan 23, 2017
f36dcae
adapt NullPointer[1-4] regression tests
mgudemann Jan 23, 2017
39fb017
default ctor for java_convert_methodt::variablet
mgudemann Jan 23, 2017
f5c89d0
take tautschnig's comments into account
mgudemann Jan 23, 2017
39c3cf7
assert known Java object size
mgudemann Jan 24, 2017
196dd5b
remove unused skip_initialize
mgudemann Jan 24, 2017
31b25f7
remove TODOs from expr2java
mgudemann Jan 24, 2017
c1101ea
beautification
mgudemann Jan 24, 2017
5e6f7ef
change "* "->" *", too
mgudemann Jan 24, 2017
669a5b0
adapt NullPointer2 regression test
mgudemann Jan 25, 2017
eb71f2c
adapt interface in CEGIS with default values
mgudemann Jan 25, 2017
a0e251f
whitespace in front of {
mgudemann Jan 25, 2017
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
2 changes: 1 addition & 1 deletion regression/cbmc-java/NullPointer1/test.desc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ NullPointer1.class
--pointer-check --stop-on-fail
^EXIT=10$
^SIGNAL=0$
^ file NullPointer1.java line 16$
^ file NullPointer1.java line 16 function java::NullPointer1.main:(\[Ljava/lang/String;)V$
^VERIFICATION FAILED$
--
^warning: ignoring
2 changes: 1 addition & 1 deletion regression/cbmc-java/NullPointer2/test.desc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ NullPointer2.class
--pointer-check --stop-on-fail
^EXIT=10$
^SIGNAL=0$
^ file NullPointer2.java line 9$
^ file NullPointer2.java line 9 function java::NullPointer2.main:(\[Ljava/lang/String;)V$
^VERIFICATION FAILED$
--
^warning: ignoring
2 changes: 1 addition & 1 deletion regression/cbmc-java/NullPointer3/test.desc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ NullPointer3.class
--pointer-check --stop-on-fail
^EXIT=10$
^SIGNAL=0$
^ file NullPointer3.java line 5$
^ file NullPointer3.java line 5 function java::NullPointer3.main:(\[Ljava/lang/String;)V bytecode_index 1$
^VERIFICATION FAILED$
--
^warning: ignoring
2 changes: 1 addition & 1 deletion regression/cbmc-java/NullPointer4/test.desc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ NullPointer4.class
--pointer-check --stop-on-fail
^EXIT=10$
^SIGNAL=0$
^ file NullPointer4.java line 6$
^ file NullPointer4.java line 6 function java::NullPointer4.main:(\[Ljava/lang/String;)V$
^VERIFICATION FAILED$
--
^warning: ignoring
2 changes: 1 addition & 1 deletion src/cegis/refactor/constraint/constraint_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void create_or_redirect_entry(symbol_tablet &st, goto_functionst &gf)
if (fmap.end() == it)
{
config.main=CONSTRAINT_CALLER;
assert(!java_entry_point(st, ID_empty, msg));
assert(!java_entry_point(st, ID_empty, msg, false, 0));
goto_convert(CPROVER_INIT, st, gf, msg);
goto_convert(goto_functionst::entry_point(), st, gf, msg);
} else
Expand Down
3 changes: 2 additions & 1 deletion src/java_bytecode/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ SRC = java_bytecode_language.cpp java_bytecode_parse_tree.cpp \
java_bytecode_typecheck_type.cpp java_bytecode_internal_additions.cpp \
java_root_class.cpp java_bytecode_parser.cpp bytecode_info.cpp \
java_class_loader.cpp jar_file.cpp java_object_factory.cpp \
java_bytecode_convert_method.cpp java_local_variable_table.cpp
java_bytecode_convert_method.cpp java_local_variable_table.cpp \
java_pointer_casts.cpp java_utils.cpp

INCLUDES= -I ..

Expand Down
98 changes: 51 additions & 47 deletions src/java_bytecode/expr2java.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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+='=';
}
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -348,7 +337,8 @@ std::string expr2javat::convert_rec(

if(code_type.has_ellipsis())
{
if(!parameters.empty()) dest+=", ";
if(!parameters.empty())
dest+=", ";
dest+="...";
}

Expand Down Expand Up @@ -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")
Copy link
Collaborator

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.

Copy link
Contributor Author

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

fef446e5dc3be5448c7af7be73f487d52738f7c5
Author:     kroening <kroening@6afb6bc1-c8e4-404c-8f48-9ae832c5b171>
AuthorDate: Sat Jun 6 11:16:51 2015 +0000
Commit:     kroening <kroening@6afb6bc1-c8e4-404c-8f48-9ae832c5b171>
CommitDate: Sat Jun 6 11:16:51 2015 +0000

Copy link
Collaborator

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")?

Copy link
Member

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.

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 ||
Expand All @@ -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))
Copy link
Member

Choose a reason for hiding this comment

The 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);
}
Expand All @@ -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);
Expand Down
49 changes: 45 additions & 4 deletions src/java_bytecode/expr2java.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading