|
13 | 13 |
|
14 | 14 | #include <iomanip>
|
15 | 15 |
|
| 16 | +#include <util/std_expr.h> |
| 17 | +#include <util/prefix.h> |
16 | 18 | #include <util/arith_tools.h>
|
17 | 19 | #include <util/unicode.h>
|
18 | 20 |
|
|
22 | 24 | #include "java_types.h"
|
23 | 25 | #include "java_utils.h"
|
24 | 26 | #include "java_root_class.h"
|
| 27 | +#include "java_string_library_preprocess.h" |
25 | 28 |
|
26 | 29 | void java_bytecode_typecheckt::typecheck_expr(exprt &expr)
|
27 | 30 | {
|
@@ -95,7 +98,8 @@ static std::string escape_non_alnum(const std::string &toescape)
|
95 | 98 | static array_exprt utf16_to_array(const std::wstring &in)
|
96 | 99 | {
|
97 | 100 | const auto jchar=java_char_type();
|
98 |
| - array_exprt ret(array_typet(jchar, infinity_exprt(java_int_type()))); |
| 101 | + array_exprt ret( |
| 102 | + array_typet(jchar, from_integer(in.length(), java_int_type()))); |
99 | 103 | for(const auto c : in)
|
100 | 104 | ret.copy_to_operands(from_integer(c, jchar));
|
101 | 105 | return ret;
|
@@ -141,33 +145,51 @@ void java_bytecode_typecheckt::typecheck_expr_java_string_literal(exprt &expr)
|
141 | 145 | {
|
142 | 146 | struct_exprt literal_init(new_symbol.type);
|
143 | 147 | literal_init.move_to_operands(jlo_init);
|
| 148 | + literal_init.copy_to_operands( |
| 149 | + from_integer(id2string(value).size(), jls_struct.components()[1].type())); |
144 | 150 |
|
145 | 151 | // Initialize the string with a constant utf-16 array:
|
146 | 152 | symbolt array_symbol;
|
147 | 153 | array_symbol.name=escaped_symbol_name+"_constarray";
|
148 |
| - array_symbol.type=array_typet( |
149 |
| - java_char_type(), infinity_exprt(java_int_type())); |
150 | 154 | array_symbol.base_name="Literal_constarray";
|
| 155 | + // TODO: this should be obtained from java_string_library_preprocess |
151 | 156 | array_symbol.pretty_name=value;
|
152 | 157 | array_symbol.mode=ID_java;
|
153 | 158 | array_symbol.is_type=false;
|
154 | 159 | array_symbol.is_lvalue=true;
|
155 | 160 | // These are basically const global data:
|
156 | 161 | array_symbol.is_static_lifetime=true;
|
157 | 162 | array_symbol.is_state_var=true;
|
158 |
| - auto literal_array=utf16_to_array( |
159 |
| - utf8_to_utf16_little_endian(id2string(value))); |
160 |
| - array_symbol.value=literal_array; |
| 163 | + array_symbol.value = |
| 164 | + utf16_to_array(utf8_to_utf16_little_endian(id2string(value))); |
| 165 | + array_symbol.type = array_symbol.value.type(); |
161 | 166 |
|
162 | 167 | if(symbol_table.add(array_symbol))
|
163 | 168 | throw "failed to add constarray symbol to symbol table";
|
164 | 169 |
|
165 |
| - literal_init.copy_to_operands( |
166 |
| - from_integer(literal_array.operands().size(), |
167 |
| - jls_struct.components()[1].type())); |
168 |
| - literal_init.copy_to_operands( |
169 |
| - address_of_exprt(array_symbol.symbol_expr())); |
170 |
| - |
| 170 | + const symbol_exprt array_expr = array_symbol.symbol_expr(); |
| 171 | + const address_of_exprt first_index( |
| 172 | + index_exprt(array_expr, from_integer(0, java_int_type()))); |
| 173 | + literal_init.copy_to_operands(first_index); |
| 174 | + |
| 175 | + // Associate array with pointer |
| 176 | + symbolt return_symbol; |
| 177 | + return_symbol.name = "return_value_" + escaped_symbol_name; |
| 178 | + return_symbol.base_name = escaped_symbol_name; |
| 179 | + return_symbol.pretty_name = "return_value"; |
| 180 | + return_symbol.mode = ID_java; |
| 181 | + return_symbol.is_type = false; |
| 182 | + return_symbol.is_lvalue = true; |
| 183 | + return_symbol.is_static_lifetime = true; |
| 184 | + return_symbol.is_state_var = true; |
| 185 | + return_symbol.value = make_function_application( |
| 186 | + ID_cprover_associate_array_to_pointer_func, |
| 187 | + {array_symbol.value, first_index}, |
| 188 | + java_int_type(), |
| 189 | + symbol_table); |
| 190 | + return_symbol.type = return_symbol.value.type(); |
| 191 | + if(symbol_table.add(return_symbol)) |
| 192 | + throw "failed to add return symbol to symbol table"; |
171 | 193 | new_symbol.value=literal_init;
|
172 | 194 | }
|
173 | 195 | else if(jls_struct.components().size()>=1 &&
|
|
0 commit comments