@@ -1678,6 +1678,59 @@ codet java_string_library_preprocesst::make_copy_constructor_code(
1678
1678
return code;
1679
1679
}
1680
1680
1681
+ // / Used to provide code for constructor from a char array.
1682
+ // / The implementation is similar to substring except the 3rd argument is a
1683
+ // / count instead of end index
1684
+ // / \param type: type of the function call
1685
+ // / \param loc: location in the program_invocation_name
1686
+ // / \param symbol_table: symbol table
1687
+ // / \return code implementing String intitialization from a char array and
1688
+ // / arguments offset and end.
1689
+ codet java_string_library_preprocesst::make_init_from_array_code (
1690
+ const code_typet &type,
1691
+ const source_locationt &loc,
1692
+ symbol_tablet &symbol_table)
1693
+ {
1694
+ // Code for the output
1695
+ code_blockt code;
1696
+
1697
+ code_typet::parameterst params = type.parameters ();
1698
+ PRECONDITION (params.size () == 4 );
1699
+ exprt::operandst args =
1700
+ process_parameters (type.parameters (), loc, symbol_table, code);
1701
+ INVARIANT (
1702
+ args.size () == 4 , " process_parameters preserves number of arguments" );
1703
+
1704
+ // / \todo this assumes the array to be constant between all calls to
1705
+ // / string primitives, which may not be true in general.
1706
+ refined_string_exprt string_arg = to_string_expr (args[1 ]);
1707
+ add_pointer_to_array_association (
1708
+ string_arg.content (),
1709
+ dereference_exprt (
1710
+ string_arg.content (),
1711
+ array_typet (java_char_type (), infinity_exprt (java_int_type ()))),
1712
+ symbol_table,
1713
+ loc,
1714
+ code);
1715
+
1716
+ // The third argument is `count`, whereas the third argument of substring
1717
+ // is `end` which corresponds to `offset+count`
1718
+ refined_string_exprt string_expr = string_expr_of_function (
1719
+ ID_cprover_string_substring_func,
1720
+ {args[1 ], args[2 ], plus_exprt (args[2 ], args[3 ])},
1721
+ loc,
1722
+ symbol_table,
1723
+ code);
1724
+
1725
+ // Assign string_expr to `this` object
1726
+ symbol_exprt arg_this (params[0 ].get_identifier (), params[0 ].type ());
1727
+ code.add (
1728
+ code_assign_string_expr_to_java_string (
1729
+ arg_this, string_expr, symbol_table));
1730
+
1731
+ return code;
1732
+ }
1733
+
1681
1734
// / Generates code for the String.length method
1682
1735
// / \param type: type of the function
1683
1736
// / \param loc: location in the source
@@ -1788,12 +1841,12 @@ void java_string_library_preprocesst::initialize_conversion_table()
1788
1841
std::placeholders::_1,
1789
1842
std::placeholders::_2,
1790
1843
std::placeholders::_3);
1791
- cprover_equivalent_to_java_constructor
1792
- [ " java::java.lang.String.<init>:([C)V " ]=
1793
- ID_cprover_string_copy_func;
1794
- cprover_equivalent_to_java_constructor
1795
- [ " java::java.lang.String.<init>:([CII)V " ]=
1796
- ID_cprover_string_copy_func ;
1844
+ conversion_table[ " java::java.lang.String.<init>:([CII)V " ] = std::bind (
1845
+ &java_string_library_preprocesst::make_init_from_array_code,
1846
+ this ,
1847
+ std::placeholders::_1,
1848
+ std::placeholders::_2,
1849
+ std::placeholders::_3) ;
1797
1850
cprover_equivalent_to_java_constructor
1798
1851
[" java::java.lang.String.<init>:()V" ]=
1799
1852
ID_cprover_string_empty_string_func;
0 commit comments