Skip to content

Commit 9142f5e

Browse files
Simplify make_char_array_for_char_pointer
The previous version was making make_char_array_for_char_pointer look more complicated than it actually is, this version should be much clearer.
1 parent 0174050 commit 9142f5e

File tree

1 file changed

+16
-31
lines changed

1 file changed

+16
-31
lines changed

src/solvers/refinement/string_constraint_generator_main.cpp

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -184,52 +184,37 @@ array_string_exprt array_poolt::make_char_array_for_char_pointer(
184184
PRECONDITION(
185185
char_array_type.subtype().id() == ID_unsignedbv ||
186186
char_array_type.subtype().id() == ID_signedbv);
187-
std::string symbol_name;
188-
if(
189-
char_pointer.id() == ID_address_of &&
190-
(to_address_of_expr(char_pointer).object().id() == ID_index) &&
191-
char_pointer.op0().op0().id() == ID_array)
192-
{
193-
// Do not replace constant arrays
194-
return to_array_string_expr(
195-
to_index_expr(to_address_of_expr(char_pointer).object()).array());
196-
}
197-
else if(char_pointer.id() == ID_address_of)
198-
{
199-
symbol_name = "char_array_of_address";
200-
}
201-
else if(char_pointer.id() == ID_if)
187+
188+
if(char_pointer.id() == ID_if)
202189
{
203190
const if_exprt &if_expr = to_if_expr(char_pointer);
204191
const array_string_exprt t =
205192
make_char_array_for_char_pointer(if_expr.true_case(), char_array_type);
206193
const array_string_exprt f =
207194
make_char_array_for_char_pointer(if_expr.false_case(), char_array_type);
208-
array_typet array_type(
195+
const array_typet array_type(
209196
char_array_type.subtype(),
210197
if_exprt(
211198
if_expr.cond(),
212199
to_array_type(t.type()).size(),
213200
to_array_type(f.type()).size()));
214201
return to_array_string_expr(if_exprt(if_expr.cond(), t, f, array_type));
215202
}
216-
else if(char_pointer.id() == ID_symbol)
217-
symbol_name = "char_array_symbol";
218-
else if(char_pointer.id() == ID_member)
219-
symbol_name = "char_array_member";
220-
else if(
221-
char_pointer.id() == ID_constant &&
222-
to_constant_expr(char_pointer).get_value() == ID_NULL)
223-
symbol_name = "char_array_null";
224-
else
225-
symbol_name = "unknown_char_array";
226-
227-
array_string_exprt array_sym =
203+
const bool is_constant_array =
204+
char_pointer.id() == ID_address_of &&
205+
(to_address_of_expr(char_pointer).object().id() == ID_index) &&
206+
char_pointer.op0().op0().id() == ID_array;
207+
if(is_constant_array)
208+
{
209+
return to_array_string_expr(
210+
to_index_expr(to_address_of_expr(char_pointer).object()).array());
211+
}
212+
const std::string symbol_name = "char_array_" + id2string(char_pointer.id());
213+
const auto array_sym =
228214
to_array_string_expr(fresh_symbol(symbol_name, char_array_type));
229-
auto insert_result =
215+
const auto insert_result =
230216
arrays_of_pointers.insert(std::make_pair(char_pointer, array_sym));
231-
array_string_exprt result = to_array_string_expr(insert_result.first->second);
232-
return result;
217+
return to_array_string_expr(insert_result.first->second);
233218
}
234219

235220
void array_poolt::insert(

0 commit comments

Comments
 (0)