Skip to content

Commit 0ae71b0

Browse files
[string-preprocessing] New functions for calling string primitives in
initialization This will be used to let the string solver now about any correspondance between pointers and arrays.
1 parent e89f5e4 commit 0ae71b0

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

src/java_bytecode/java_string_library_preprocess.cpp

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,77 @@ codet java_string_library_preprocesst::code_return_function_application(
639639
return code_returnt(fun_app);
640640
}
641641

642+
exprt make_nondet_infinite_char_array(
643+
symbol_tablet &symbol_table,
644+
const source_locationt &loc,
645+
code_blockt &code)
646+
{
647+
const array_typet array_type(
648+
java_char_type(), infinity_exprt(java_int_type()));
649+
const symbolt data_sym = get_fresh_aux_symbol(
650+
array_type,
651+
"nondet_inifinite_array",
652+
"nondet_inifinite_array",
653+
loc,
654+
ID_java,
655+
symbol_table);
656+
const symbol_exprt data_expr = data_sym.symbol_expr();
657+
code.add(code_declt(data_expr));
658+
side_effect_expr_nondett nondet_data(data_expr.type());
659+
code.add(code_assignt(data_expr, nondet_data));
660+
return data_expr;
661+
}
662+
663+
void add_pointer_to_array_association(
664+
const exprt &pointer,
665+
const exprt &array,
666+
symbol_tablet &symbol_table,
667+
const source_locationt &loc,
668+
code_blockt &code)
669+
{
670+
PRECONDITION(array.type().id() == ID_array);
671+
PRECONDITION(pointer.type().id() == ID_pointer);
672+
symbolt &return_sym = get_fresh_aux_symbol(
673+
java_int_type(),
674+
"return_array",
675+
"return_array",
676+
loc,
677+
ID_java,
678+
symbol_table);
679+
exprt return_expr = return_sym.symbol_expr();
680+
code.add(code_declt(return_expr));
681+
code.add(
682+
code_assign_function_application(
683+
return_expr,
684+
ID_cprover_associate_array_to_pointer_func,
685+
{array, pointer},
686+
symbol_table));
687+
}
688+
689+
void add_array_to_length_association(
690+
const exprt &array,
691+
const exprt &length,
692+
symbol_tablet &symbol_table,
693+
const source_locationt &loc,
694+
code_blockt &code)
695+
{
696+
symbolt &return_sym = get_fresh_aux_symbol(
697+
java_int_type(),
698+
"return_array",
699+
"return_array",
700+
loc,
701+
ID_java,
702+
symbol_table);
703+
const exprt return_expr = return_sym.symbol_expr();
704+
code.add(code_declt(return_expr));
705+
code.add(
706+
code_assign_function_application(
707+
return_expr,
708+
ID_cprover_associate_length_to_array_func,
709+
{array, length},
710+
symbol_table));
711+
}
712+
642713
/// \param string_expr: a string expression
643714
/// \param function_name: the name of the function
644715
/// \param arguments: arguments of the function

src/java_bytecode/java_string_library_preprocess.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,4 +351,23 @@ class java_string_library_preprocesst:public messaget
351351
exprt get_object_at_index(const exprt &argv, int index);
352352
};
353353

354+
exprt make_nondet_infinite_char_array(
355+
symbol_tablet &symbol_table,
356+
const source_locationt &loc,
357+
code_blockt &code);
358+
359+
void add_pointer_to_array_association(
360+
const exprt &pointer,
361+
const exprt &array,
362+
symbol_tablet &symbol_table,
363+
const source_locationt &loc,
364+
code_blockt &code);
365+
366+
void add_array_to_length_association(
367+
const exprt &array,
368+
const exprt &length,
369+
symbol_tablet &symbol_table,
370+
const source_locationt &loc,
371+
code_blockt &code);
372+
354373
#endif // CPROVER_JAVA_BYTECODE_JAVA_STRING_LIBRARY_PREPROCESS_H

0 commit comments

Comments
 (0)