-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #582 from peterschrammel/update-from-master
Update test-gen-support from master
- Loading branch information
Showing
28 changed files
with
694 additions
and
481 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 |
---|---|---|
|
@@ -21,7 +21,8 @@ Author: Daniel Kroening, [email protected] | |
|
||
bool java_bytecode_typecheck( | ||
symbol_tablet &symbol_table, | ||
message_handlert &message_handler); | ||
message_handlert &message_handler, | ||
bool string_refinement_enabled); | ||
|
||
bool java_bytecode_typecheck( | ||
exprt &expr, | ||
|
@@ -33,10 +34,12 @@ class java_bytecode_typecheckt:public typecheckt | |
public: | ||
java_bytecode_typecheckt( | ||
symbol_tablet &_symbol_table, | ||
message_handlert &_message_handler): | ||
message_handlert &_message_handler, | ||
bool _string_refinement_enabled): | ||
typecheckt(_message_handler), | ||
symbol_table(_symbol_table), | ||
ns(symbol_table) | ||
ns(symbol_table), | ||
string_refinement_enabled(_string_refinement_enabled) | ||
{ | ||
} | ||
|
||
|
@@ -48,6 +51,7 @@ class java_bytecode_typecheckt:public typecheckt | |
protected: | ||
symbol_tablet &symbol_table; | ||
const namespacet ns; | ||
bool string_refinement_enabled; | ||
|
||
void typecheck_type_symbol(symbolt &); | ||
void typecheck_non_type_symbol(symbolt &); | ||
|
This file contains 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,9 +10,14 @@ Author: Daniel Kroening, [email protected] | |
|
||
#include <util/std_expr.h> | ||
#include <util/prefix.h> | ||
#include <util/arith_tools.h> | ||
#include <util/unicode.h> | ||
|
||
#include <linking/zero_initializer.h> | ||
|
||
#include "java_bytecode_typecheck.h" | ||
#include "java_pointer_casts.h" | ||
#include "java_types.h" | ||
|
||
/*******************************************************************\ | ||
|
@@ -114,6 +119,27 @@ static std::string escape_non_alnum(const std::string &toescape) | |
|
||
/*******************************************************************\ | ||
Function: utf16_to_array | ||
Inputs: `in`: wide string to convert | ||
Outputs: Returns a Java char array containing the same wchars. | ||
Purpose: Convert UCS-2 or UTF-16 to an array expression. | ||
\*******************************************************************/ | ||
|
||
static array_exprt utf16_to_array(const std::wstring &in) | ||
{ | ||
const auto jchar=java_char_type(); | ||
array_exprt ret(array_typet(jchar, infinity_exprt(java_int_type()))); | ||
for(const auto c : in) | ||
ret.copy_to_operands(from_integer(c, jchar)); | ||
return ret; | ||
} | ||
|
||
/*******************************************************************\ | ||
Function: java_bytecode_typecheckt::typecheck_expr_java_string_literal | ||
Inputs: | ||
|
@@ -136,28 +162,106 @@ void java_bytecode_typecheckt::typecheck_expr_java_string_literal(exprt &expr) | |
auto findit=symbol_table.symbols.find(escaped_symbol_name); | ||
if(findit!=symbol_table.symbols.end()) | ||
{ | ||
expr=findit->second.symbol_expr(); | ||
expr=address_of_exprt(findit->second.symbol_expr()); | ||
return; | ||
} | ||
|
||
// Create a new symbol: | ||
symbolt new_symbol; | ||
new_symbol.name=escaped_symbol_name; | ||
new_symbol.type=pointer_typet(string_type); | ||
new_symbol.type=string_type; | ||
new_symbol.base_name="Literal"; | ||
new_symbol.pretty_name=value; | ||
new_symbol.mode=ID_java; | ||
new_symbol.is_type=false; | ||
new_symbol.is_lvalue=true; | ||
new_symbol.is_static_lifetime=true; // These are basically const global data. | ||
|
||
// Regardless of string refinement setting, at least initialize | ||
// the literal with @clsid = String and @lock = false: | ||
symbol_typet jlo_symbol("java::java.lang.Object"); | ||
const auto &jlo_struct=to_struct_type(ns.follow(jlo_symbol)); | ||
struct_exprt jlo_init(jlo_symbol); | ||
const auto &jls_struct=to_struct_type(ns.follow(string_type)); | ||
|
||
jlo_init.copy_to_operands( | ||
constant_exprt( | ||
"java::java.lang.String", | ||
jlo_struct.components()[0].type())); | ||
jlo_init.copy_to_operands( | ||
from_integer( | ||
0, | ||
jlo_struct.components()[1].type())); | ||
|
||
// If string refinement *is* around, populate the actual | ||
// contents as well: | ||
if(string_refinement_enabled) | ||
{ | ||
struct_exprt literal_init(new_symbol.type); | ||
literal_init.move_to_operands(jlo_init); | ||
|
||
// Initialize the string with a constant utf-16 array: | ||
symbolt array_symbol; | ||
array_symbol.name=escaped_symbol_name+"_constarray"; | ||
array_symbol.type=array_typet( | ||
java_char_type(), infinity_exprt(java_int_type())); | ||
array_symbol.base_name="Literal_constarray"; | ||
array_symbol.pretty_name=value; | ||
array_symbol.mode=ID_java; | ||
array_symbol.is_type=false; | ||
array_symbol.is_lvalue=true; | ||
// These are basically const global data: | ||
array_symbol.is_static_lifetime=true; | ||
array_symbol.is_state_var=true; | ||
auto literal_array=utf16_to_array( | ||
utf8_to_utf16_little_endian(id2string(value))); | ||
array_symbol.value=literal_array; | ||
|
||
if(symbol_table.add(array_symbol)) | ||
throw "failed to add constarray symbol to symbol table"; | ||
|
||
literal_init.copy_to_operands( | ||
from_integer(literal_array.operands().size(), | ||
jls_struct.components()[1].type())); | ||
literal_init.copy_to_operands( | ||
address_of_exprt(array_symbol.symbol_expr())); | ||
|
||
new_symbol.value=literal_init; | ||
} | ||
else if(jls_struct.components().size()>=1 && | ||
jls_struct.components()[0].get_name()=="@java.lang.Object") | ||
{ | ||
// Case where something defined java.lang.String, so it has | ||
// a proper base class (always java.lang.Object in practical | ||
// JDKs seen so far) | ||
struct_exprt literal_init(new_symbol.type); | ||
literal_init.move_to_operands(jlo_init); | ||
for(const auto &comp : jls_struct.components()) | ||
{ | ||
if(comp.get_name()=="@java.lang.Object") | ||
continue; | ||
// Other members of JDK's java.lang.String we don't understand | ||
// without string-refinement. Just zero-init them; consider using | ||
// test-gen-like nondet object trees instead. | ||
literal_init.copy_to_operands( | ||
zero_initializer(comp.type(), expr.source_location(), ns)); | ||
} | ||
new_symbol.value=literal_init; | ||
} | ||
else if(jls_struct.get_bool(ID_incomplete_class)) | ||
{ | ||
// Case where java.lang.String was stubbed, and so directly defines | ||
// @class_identifier and @lock: | ||
new_symbol.value=jlo_init; | ||
} | ||
|
||
if(symbol_table.add(new_symbol)) | ||
{ | ||
error() << "failed to add string literal symbol to symbol table" << eom; | ||
throw 0; | ||
} | ||
|
||
expr=new_symbol.symbol_expr(); | ||
expr=address_of_exprt(new_symbol.symbol_expr()); | ||
} | ||
|
||
/*******************************************************************\ | ||
|
Oops, something went wrong.