Skip to content

Commit 3a6b400

Browse files
author
Joel Allred
committed
[preprocess] [amendments] PR 906 diffblue/test-gen#133
Changes requested by Matthias Guedemann, Peter Schrammel, and Chris Smowton.
1 parent 3dabbac commit 3a6b400

5 files changed

+53
-58
lines changed

src/java_bytecode/java_bytecode_convert_class.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,11 @@ class java_bytecode_convert_classt:public messaget
4747

4848
if(parse_tree.loading_successful)
4949
convert(parse_tree.parsed_class);
50-
else if(!string_preprocess.add_string_type_success(
51-
parse_tree.parsed_class.name, symbol_table))
50+
else if(string_preprocess.is_known_string_type(
51+
parse_tree.parsed_class.name))
52+
string_preprocess.add_string_type(
53+
parse_tree.parsed_class.name, symbol_table);
54+
else
5255
generate_class_stub(parse_tree.parsed_class.name);
5356
}
5457

src/java_bytecode/java_bytecode_convert_method.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1536,8 +1536,8 @@ codet java_bytecode_convert_methodt::convert_instructions(
15361536
symbol.name,
15371537
symbol_table);
15381538

1539-
// functions of the String libraries can have code
1540-
// generated for them
1539+
// The string refinement module may provide a definition for this
1540+
// function.
15411541
symbol.value=string_preprocess.code_for_function(
15421542
id, to_code_type(symbol.type), loc, symbol_table);
15431543

src/java_bytecode/java_object_factory.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,8 @@ exprt allocate_dynamic_object(
156156
pointer_typet(allocate_type),
157157
"malloc_site");
158158
code_assignt assign=code_assignt(malloc_sym.symbol_expr(), malloc_expr);
159-
code_assignt &malloc_assign=assign;
160-
malloc_assign.add_source_location()=loc;
161-
output_code.copy_to_operands(malloc_assign);
159+
assign.add_source_location()=loc;
160+
output_code.copy_to_operands(assign);
162161
malloc_expr=malloc_sym.symbol_expr();
163162
if(cast_needed)
164163
malloc_expr=typecast_exprt(malloc_expr, target_expr.type());

src/java_bytecode/java_string_library_preprocess.cpp

+37-41
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Date: April 2017
2424

2525
/*******************************************************************\
2626
27-
Function: java_string_library_preprocesst::check_java_type
27+
Function: java_string_library_preprocesst::java_type_matches_tag
2828
2929
Inputs:
3030
type - a type
@@ -35,7 +35,7 @@ Function: java_string_library_preprocesst::check_java_type
3535
3636
\*******************************************************************/
3737

38-
bool java_string_library_preprocesst::check_java_type(
38+
bool java_string_library_preprocesst::java_type_matches_tag(
3939
const typet &type, const std::string &tag)
4040
{
4141
if(type.id()==ID_symbol)
@@ -86,7 +86,7 @@ Function: java_string_library_preprocesst::is_java_string_type
8686
bool java_string_library_preprocesst::is_java_string_type(
8787
const typet &type)
8888
{
89-
return check_java_type(type, "java.lang.String");
89+
return java_type_matches_tag(type, "java.lang.String");
9090
}
9191

9292
/*******************************************************************\
@@ -102,7 +102,7 @@ Function: java_string_library_preprocesst::is_java_string_builder_type
102102
bool java_string_library_preprocesst::is_java_string_builder_type(
103103
const typet &type)
104104
{
105-
return check_java_type(type, "java.lang.StringBuilder");
105+
return java_type_matches_tag(type, "java.lang.StringBuilder");
106106
}
107107

108108
/*******************************************************************\
@@ -141,7 +141,7 @@ Function: java_string_library_preprocesst::is_java_string_buffer_type
141141
bool java_string_library_preprocesst::is_java_string_buffer_type(
142142
const typet &type)
143143
{
144-
return check_java_type(type, "java.lang.StringBuffer");
144+
return java_type_matches_tag(type, "java.lang.StringBuffer");
145145
}
146146

147147
/*******************************************************************\
@@ -180,7 +180,7 @@ Function: java_string_library_preprocesst::is_java_char_sequence_type
180180
bool java_string_library_preprocesst::is_java_char_sequence_type(
181181
const typet &type)
182182
{
183-
return check_java_type(type, "java.lang.CharSequence");
183+
return java_type_matches_tag(type, "java.lang.CharSequence");
184184
}
185185

186186
/*******************************************************************\
@@ -219,7 +219,7 @@ Function: java_string_library_preprocesst::is_java_char_array_type
219219
bool java_string_library_preprocesst::is_java_char_array_type(
220220
const typet &type)
221221
{
222-
return check_java_type(type, "array[char]");
222+
return java_type_matches_tag(type, "array[char]");
223223
}
224224

225225
/*******************************************************************\
@@ -318,6 +318,7 @@ void java_string_library_preprocesst::add_string_type(
318318
symbolt string_symbol;
319319
string_symbol.name="java::"+id2string(class_name);
320320
string_symbol.base_name=id2string(class_name);
321+
string_symbol.pretty_name=id2string(class_name);
321322
string_symbol.type=string_type;
322323
string_symbol.is_type=true;
323324

@@ -374,6 +375,7 @@ void java_string_library_preprocesst::declare_function(
374375
{
375376
auxiliary_symbolt func_symbol;
376377
func_symbol.base_name=function_name;
378+
func_symbol.pretty_name=function_name;
377379
func_symbol.is_static_lifetime=false;
378380
func_symbol.mode=ID_java;
379381
func_symbol.name=function_name;
@@ -492,7 +494,7 @@ exprt::operandst java_string_library_preprocesst::process_operands(
492494
}
493495
else if(is_java_char_array_pointer_type(p.type()))
494496
{
495-
ops.push_back(process_char_array(p, loc, symbol_table, init_code));
497+
ops.push_back(replace_char_array(p, loc, symbol_table, init_code));
496498
}
497499
else
498500
{
@@ -504,7 +506,7 @@ exprt::operandst java_string_library_preprocesst::process_operands(
504506

505507
/*******************************************************************\
506508
507-
Function: java_string_library_preprocesst::process_operands_for_equals
509+
Function: java_string_library_preprocesst::process_equals_function_operands
508510
509511
Inputs:
510512
operands - a list of expressions
@@ -521,7 +523,8 @@ Function: java_string_library_preprocesst::process_operands_for_equals
521523
522524
\*******************************************************************/
523525

524-
exprt::operandst java_string_library_preprocesst::process_operands_for_equals(
526+
exprt::operandst
527+
java_string_library_preprocesst::process_equals_function_operands(
525528
const exprt::operandst &operands,
526529
const source_locationt &loc,
527530
symbol_tablet &symbol_table,
@@ -656,13 +659,13 @@ exprt java_string_library_preprocesst::get_data(
656659

657660
/*******************************************************************\
658661
659-
Function: string_refine_preprocesst::process_char_array
662+
Function: string_refine_preprocesst::replace_char_array
660663
661664
Inputs:
662665
array_pointer - an expression of type char array pointer
663666
loc - location in the source
664667
symbol_table - symbol table
665-
code - code block, in which some assignements will be added
668+
code - code block, in which some assignments will be added
666669
667670
Output: a string expression
668671
@@ -671,7 +674,7 @@ Function: string_refine_preprocesst::process_char_array
671674
672675
\*******************************************************************/
673676

674-
string_exprt java_string_library_preprocesst::process_char_array(
677+
string_exprt java_string_library_preprocesst::replace_char_array(
675678
const exprt &array_pointer,
676679
const source_locationt &loc,
677680
symbol_tablet &symbol_table,
@@ -1234,7 +1237,7 @@ Function: java_string_library_preprocesst::make_equals_code
12341237
12351238
\*******************************************************************/
12361239

1237-
codet java_string_library_preprocesst::make_equals_code(
1240+
codet java_string_library_preprocesst::make_equals_function_code(
12381241
const code_typet &type,
12391242
const source_locationt &loc,
12401243
symbol_tablet &symbol_table)
@@ -1247,7 +1250,7 @@ codet java_string_library_preprocesst::make_equals_code(
12471250
symbol_exprt sym(p.get_identifier(), p.type());
12481251
ops.push_back(sym);
12491252
}
1250-
exprt::operandst args=process_operands_for_equals(
1253+
exprt::operandst args=process_equals_function_operands(
12511254
ops, loc, symbol_table, code);
12521255
code.copy_to_operands(code_return_function_application(
12531256
ID_cprover_string_equal_func, args, type.return_type(), symbol_table));
@@ -1714,7 +1717,7 @@ codet java_string_library_preprocesst::make_function_from_call(
17141717
> string = string_expr_to_string(string)
17151718
> return string
17161719
1717-
Purpose: Povide code for a function that calls a function from the
1720+
Purpose: Provide code for a function that calls a function from the
17181721
solver and return the string_expr result as a Java string.
17191722
17201723
\*******************************************************************/
@@ -1785,8 +1788,8 @@ exprt java_string_library_preprocesst::code_for_function(
17851788
return make_string_returning_function_from_call(
17861789
it_id->second, type, loc, symbol_table);
17871790

1788-
it_id=cprover_equivalent_to_java_initialization_function.find(function_id);
1789-
if(it_id!=cprover_equivalent_to_java_initialization_function.end())
1791+
it_id=cprover_equivalent_to_java_constructor.find(function_id);
1792+
if(it_id!=cprover_equivalent_to_java_constructor.end())
17901793
return make_init_function_from_call(
17911794
it_id->second, type, loc, symbol_table);
17921795

@@ -1809,36 +1812,29 @@ exprt java_string_library_preprocesst::code_for_function(
18091812

18101813
/*******************************************************************\
18111814
1812-
Function: java_string_library_preprocesst::add_string_type_success
1815+
Function: java_string_library_preprocesst::is_known_string_type
18131816
18141817
Inputs:
18151818
class_name - name of the class
1816-
symbol_table - a symbol table
18171819
18181820
Outputs: True if the type is one that is known to our preprocessing,
18191821
false otherwise
18201822
1821-
Purpose: Declare a class for String types that are used in the program
1823+
Purpose: Check whether a class name is known as a string type.
18221824
18231825
\*******************************************************************/
18241826

1825-
bool java_string_library_preprocesst::add_string_type_success(
1826-
irep_idt class_name, symbol_tablet &symbol_table)
1827+
bool java_string_library_preprocesst::is_known_string_type(
1828+
irep_idt class_name)
18271829
{
1828-
if(string_types.find(class_name)!=string_types.end())
1829-
{
1830-
add_string_type(class_name, symbol_table);
1831-
return true;
1832-
}
1833-
else
1834-
return false;
1830+
return string_types.find(class_name)!=string_types.end();
18351831
}
18361832

18371833
/*******************************************************************\
18381834
18391835
Function: java_string_library_preprocesst::initialize_conversion_table
18401836
1841-
Purpose: fill maps with correspondance from java method names to
1837+
Purpose: fill maps with correspondence from java method names to
18421838
conversion functions
18431839
18441840
\*******************************************************************/
@@ -1854,19 +1850,19 @@ void java_string_library_preprocesst::initialize_conversion_table()
18541850
"java.lang.StringBuffer"};
18551851

18561852
// String library
1857-
cprover_equivalent_to_java_initialization_function
1853+
cprover_equivalent_to_java_constructor
18581854
["java::java.lang.String.<init>:(Ljava/lang/String;)V"]=
18591855
ID_cprover_string_copy_func;
1860-
cprover_equivalent_to_java_initialization_function
1856+
cprover_equivalent_to_java_constructor
18611857
["java::java.lang.String.<init>:(Ljava/lang/StringBuilder;)V"]=
18621858
ID_cprover_string_copy_func;
1863-
cprover_equivalent_to_java_initialization_function
1859+
cprover_equivalent_to_java_constructor
18641860
["java::java.lang.String.<init>:([C)V"]=
18651861
ID_cprover_string_copy_func;
1866-
cprover_equivalent_to_java_initialization_function
1862+
cprover_equivalent_to_java_constructor
18671863
["java::java.lang.String.<init>:([CII)V"]=
18681864
ID_cprover_string_copy_func;
1869-
cprover_equivalent_to_java_initialization_function
1865+
cprover_equivalent_to_java_constructor
18701866
["java::java.lang.String.<init>:()V"]=
18711867
ID_cprover_string_empty_string_func;
18721868
// Not supported java.lang.String.<init>:(Ljava/lang/StringBuffer;)
@@ -1905,7 +1901,7 @@ void java_string_library_preprocesst::initialize_conversion_table()
19051901

19061902
conversion_table["java::java.lang.String.equals:(Ljava/lang/Object;)Z"]=
19071903
std::bind(
1908-
&java_string_library_preprocesst::make_equals_code,
1904+
&java_string_library_preprocesst::make_equals_function_code,
19091905
this,
19101906
std::placeholders::_1,
19111907
std::placeholders::_2,
@@ -2026,10 +2022,10 @@ void java_string_library_preprocesst::initialize_conversion_table()
20262022
// Not supported "java.lang.String.valueOf:(LObject;)"
20272023

20282024
// StringBuilder library
2029-
cprover_equivalent_to_java_initialization_function
2025+
cprover_equivalent_to_java_constructor
20302026
["java::java.lang.StringBuilder.<init>:(Ljava/lang/String;)V"]=
20312027
ID_cprover_string_copy_func;
2032-
cprover_equivalent_to_java_initialization_function
2028+
cprover_equivalent_to_java_constructor
20332029
["java::java.lang.StringBuilder.<init>:()V"]=
20342030
ID_cprover_string_empty_string_func;
20352031

@@ -2156,10 +2152,10 @@ void java_string_library_preprocesst::initialize_conversion_table()
21562152
// TODO clean irep ids from insert_char_array etc...
21572153

21582154
// StringBuffer library
2159-
cprover_equivalent_to_java_initialization_function
2155+
cprover_equivalent_to_java_constructor
21602156
["java::java.lang.StringBuffer.<init>:(Ljava/lang/String;)V"]=
21612157
ID_cprover_string_copy_func;
2162-
cprover_equivalent_to_java_initialization_function
2158+
cprover_equivalent_to_java_constructor
21632159
["java::java.lang.StringBuffer.<init>:()V"]=
21642160
ID_cprover_string_empty_string_func;
21652161

src/java_bytecode/java_string_library_preprocess.h

+7-10
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,11 @@ class java_string_library_preprocesst:public messaget
4343
{
4444
return character_preprocess.replace_character_call(call);
4545
}
46-
47-
bool add_string_type_success(
48-
irep_idt class_name, symbol_tablet &symbol_table);
46+
void add_string_type(const irep_idt &class_name, symbol_tablet &symbol_table);
47+
bool is_known_string_type(irep_idt class_name);
4948

5049
private:
51-
static bool check_java_type(const typet &type, const std::string &tag);
50+
static bool java_type_matches_tag(const typet &type, const std::string &tag);
5251
static bool is_java_string_pointer_type(const typet &type);
5352
static bool is_java_string_type(const typet &type);
5453
static bool is_java_string_builder_type(const typet &type);
@@ -93,7 +92,7 @@ class java_string_library_preprocesst:public messaget
9392

9493
// Some Java initialization function initialize strings with the
9594
// same result as some function of the solver
96-
id_mapt cprover_equivalent_to_java_initialization_function;
95+
id_mapt cprover_equivalent_to_java_constructor;
9796

9897
// Some Java functions have an equivalent in the solver except that
9998
// in addition they assign the result to the object on which it is called
@@ -113,7 +112,7 @@ class java_string_library_preprocesst:public messaget
113112
const source_locationt &loc,
114113
symbol_tablet &symbol_table);
115114

116-
codet make_equals_code(
115+
codet make_equals_function_code(
117116
const code_typet &type,
118117
const source_locationt &loc,
119118
symbol_tablet &symbol_table);
@@ -163,13 +162,13 @@ class java_string_library_preprocesst:public messaget
163162
symbol_tablet &symbol_table,
164163
code_blockt &init_code);
165164

166-
exprt::operandst process_operands_for_equals(
165+
exprt::operandst process_equals_function_operands(
167166
const exprt::operandst &operands,
168167
const source_locationt &loc,
169168
symbol_tablet &symbol_table,
170169
code_blockt &init_code);
171170

172-
string_exprt process_char_array(
171+
string_exprt replace_char_array(
173172
const exprt &array_pointer,
174173
const source_locationt &loc,
175174
symbol_tablet &symbol_table,
@@ -266,8 +265,6 @@ class java_string_library_preprocesst:public messaget
266265
const std::string &s,
267266
symbol_tablet &symbol_table);
268267

269-
void add_string_type(const irep_idt &class_name, symbol_tablet &symbol_table);
270-
271268
exprt string_literal(const std::string &s);
272269

273270
codet make_function_from_call(

0 commit comments

Comments
 (0)