Skip to content

Commit 03fb38f

Browse files
author
Owen Jones
committed
Turn on Long.toString and improve implementation
After comparing them both, the constructive approach won out over the non-constructive one. Also fixed a bug that the radix wasn't being evaluated properly because we weren't calling simplify_expr.
1 parent 9dd1152 commit 03fb38f

File tree

4 files changed

+321
-320
lines changed

4 files changed

+321
-320
lines changed

src/java_bytecode/java_string_library_preprocess.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2300,6 +2300,12 @@ void java_string_library_preprocesst::initialize_conversion_table()
23002300
cprover_equivalent_to_java_string_returning_function
23012301
["java::java.lang.Integer.toString:(II)Ljava/lang/String;"]=
23022302
ID_cprover_string_of_int_func;
2303+
cprover_equivalent_to_java_string_returning_function
2304+
["java::java.lang.Long.toString:(J)Ljava/lang/String;"]=
2305+
ID_cprover_string_of_int_func;
2306+
cprover_equivalent_to_java_string_returning_function
2307+
["java::java.lang.Long.toString:(JI)Ljava/lang/String;"]=
2308+
ID_cprover_string_of_int_func;
23032309
conversion_table
23042310
["java::java.lang.Object.getClass:()Ljava/lang/Class;"]=
23052311
std::bind(

src/solvers/refinement/string_constraint_generator.h

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ class string_constraint_generatort: messaget
3333
// string constraints for different string functions and add them
3434
// to the axiom list.
3535

36-
string_constraint_generatort():
36+
string_constraint_generatort(namespacet _ns):
3737
max_string_length(std::numeric_limits<size_t>::max()),
38-
force_printable_characters(false)
38+
force_printable_characters(false),
39+
ns(_ns)
3940
{ }
4041

4142
// Constraints on the maximal length of strings
@@ -107,6 +108,7 @@ class string_constraint_generatort: messaget
107108
const std::size_t MAX_DOUBLE_LENGTH=30;
108109

109110
std::map<function_application_exprt, exprt> function_application_cache;
111+
namespacet ns;
110112

111113
static irep_idt extract_java_string(const symbol_exprt &s);
112114

@@ -305,16 +307,21 @@ class string_constraint_generatort: messaget
305307
exprt add_axioms_for_offset_by_code_point(
306308
const function_application_exprt &f);
307309

308-
exprt add_axioms_for_characters_in_integer_string(
309-
const symbol_exprt& x,
310-
const typet& type,
311-
const typet& char_type,
312-
const typet& index_type,
313-
const string_exprt& str,
310+
void add_axioms_for_characters_in_integer_string(
311+
const exprt &input_int,
312+
const typet &type,
313+
const bool strict_formatting,
314+
const string_exprt &str,
314315
const std::size_t max_string_length,
315-
const exprt& radix);
316+
const exprt &radix,
317+
const unsigned long radix_ul);
316318
void add_axioms_for_correct_number_format(
317-
const string_exprt &str, const exprt &radix, std::size_t max_size);
319+
const exprt &input_int,
320+
const string_exprt &str,
321+
const exprt &radix_as_char,
322+
const unsigned long radix_ul,
323+
const std::size_t max_size,
324+
const bool strict_formatting);
318325
exprt add_axioms_for_parse_int(const function_application_exprt &f);
319326
exprt add_axioms_for_to_char_array(const function_application_exprt &f);
320327
exprt add_axioms_for_compare_to(const function_application_exprt &f);
@@ -348,18 +355,21 @@ class string_constraint_generatort: messaget
348355
exprt char1, exprt char2, exprt char_a, exprt char_A, exprt char_Z);
349356
bool is_constant_string(const string_exprt &expr) const;
350357
string_exprt empty_string(const refined_string_typet &ref_type);
358+
unsigned long to_integer_or_default(const exprt &expr, unsigned long def);
351359
};
352360

353-
exprt is_digit_with_radix(const exprt &chr, const exprt &radix);
354-
exprt is_digit_with_radix_lower_case(
355-
const exprt &chr, const exprt &radix_char_type, unsigned long radix=36ul);
361+
exprt is_digit_with_radix(
362+
const exprt &chr,
363+
const bool strict_formatting,
364+
const exprt &radix_as_char,
365+
const unsigned long radix_ul);
356366
exprt get_numeric_value_from_character(
357367
const exprt &chr,
358368
const typet &char_type,
359369
const typet &type,
360-
unsigned long radix=36ul);
370+
const bool strict_formatting,
371+
unsigned long radix_ul);
361372
size_t max_printed_string_length(const typet &type, unsigned long ul_radix);
362-
unsigned long to_integer_or_default(const exprt &expr, unsigned long def);
363373
std::string utf16_constant_array_to_java(
364374
const array_exprt &arr, unsigned length);
365375

0 commit comments

Comments
 (0)