Skip to content

Commit 514e6a1

Browse files
Add function to call constrain_character primitive
This is to be used during bytecode conversion to add constraints on characters.
1 parent 1d92c48 commit 514e6a1

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

src/java_bytecode/java_string_library_preprocess.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,38 @@ void add_array_to_length_association(
704704
symbol_table));
705705
}
706706

707+
/// Add a call to a primitive of the string solver which ensures all characters
708+
/// belong to the character set.
709+
/// \param pointer: a character pointer expression
710+
/// \param length: length of the character sequence pointed by `pointer`
711+
/// \param char_set: character set given by a range expression consisting of
712+
/// two characters separated by an hyphen.
713+
/// For instance "a-z" denotes all lower case ascii letters.
714+
/// \param symbol_table: the symbol table
715+
/// \param loc: source location
716+
/// \param code [out] : code block to which declaration and calls get added
717+
void add_character_set_constraint(
718+
const exprt &pointer,
719+
const exprt &length,
720+
const irep_idt &char_set,
721+
symbol_tablet &symbol_table,
722+
const source_locationt &loc,
723+
code_blockt &code)
724+
{
725+
PRECONDITION(pointer.type().id() == ID_pointer);
726+
symbolt &return_sym = get_fresh_aux_symbol(
727+
java_int_type(), "cnstr_added", "cnstr_added", loc, ID_java, symbol_table);
728+
const exprt return_expr = return_sym.symbol_expr();
729+
code.add(code_declt(return_expr));
730+
const constant_exprt char_set_expr(char_set, string_typet());
731+
code.add(
732+
code_assign_function_application(
733+
return_expr,
734+
ID_cprover_string_constrain_characters_func,
735+
{length, pointer, char_set_expr},
736+
symbol_table));
737+
}
738+
707739
/// Create a refined_string_exprt `str` whose content and length are fresh
708740
/// symbols, calls the string primitive with name `function_name`.
709741
/// In the arguments of the primitive `str` takes the place of the result and

src/java_bytecode/java_string_library_preprocess.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,4 +349,12 @@ void add_array_to_length_association(
349349
const source_locationt &loc,
350350
code_blockt &code);
351351

352+
void add_character_set_constraint(
353+
const exprt &pointer,
354+
const exprt &length,
355+
const irep_idt &char_set,
356+
symbol_tablet &symbol_table,
357+
const source_locationt &loc,
358+
code_blockt &code);
359+
352360
#endif // CPROVER_JAVA_BYTECODE_JAVA_STRING_LIBRARY_PREPROCESS_H

0 commit comments

Comments
 (0)