Skip to content

Commit 384772f

Browse files
committed
Add support for getting value of array of arrays
In preparation for array of struct support.
1 parent 787f76e commit 384772f

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

src/solvers/smt2_incremental/smt2_incremental_decision_procedure.cpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ smt2_incremental_decision_proceduret::get_identifier(const exprt &expr) const
367367
return {};
368368
}
369369

370-
array_exprt smt2_incremental_decision_proceduret::get_expr(
370+
optionalt<exprt> smt2_incremental_decision_proceduret::get_expr(
371371
const smt_termt &array,
372372
const array_typet &type) const
373373
{
@@ -388,16 +388,25 @@ array_exprt smt2_incremental_decision_proceduret::get_expr(
388388
pointer_sizes_map,
389389
object_size_function.make_application,
390390
is_dynamic_object_function.make_application);
391-
elements.push_back(get_expr(
392-
smt_array_theoryt::select(array, index_term), type.element_type()));
391+
auto element = get_expr(
392+
smt_array_theoryt::select(array, index_term), type.element_type());
393+
if(!element)
394+
return {};
395+
elements.push_back(std::move(*element));
393396
}
394397
return array_exprt{elements, type};
395398
}
396399

397-
exprt smt2_incremental_decision_proceduret::get_expr(
400+
optionalt<exprt> smt2_incremental_decision_proceduret::get_expr(
398401
const smt_termt &descriptor,
399402
const typet &type) const
400403
{
404+
if(const auto array_type = type_try_dynamic_cast<array_typet>(type))
405+
{
406+
if(array_type->is_incomplete())
407+
return {};
408+
return get_expr(descriptor, *array_type);
409+
}
401410
const smt_get_value_commandt get_value_command{descriptor};
402411
const smt_responset response = get_response_to_command(
403412
*solver_process, get_value_command, identifier_table);
@@ -483,13 +492,9 @@ exprt smt2_incremental_decision_proceduret::get(const exprt &expr) const
483492
irep_pretty_diagnosticst{expr});
484493
return build_expr_based_on_getting_operands(expr, *this);
485494
}
486-
if(const auto array_type = type_try_dynamic_cast<array_typet>(expr.type()))
487-
{
488-
if(array_type->is_incomplete())
489-
return expr;
490-
return get_expr(*descriptor, *array_type);
491-
}
492-
return get_expr(*descriptor, expr.type());
495+
if(auto result = get_expr(*descriptor, expr.type()))
496+
return std::move(*result);
497+
return expr;
493498
}
494499

495500
void smt2_incremental_decision_proceduret::print_assignment(

src/solvers/smt2_incremental/smt2_incremental_decision_procedure.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,10 @@ class smt2_incremental_decision_proceduret final
5454
/// Gets the value of \p descriptor from the solver and returns the solver
5555
/// response expressed as an exprt of type \p type. This is an implementation
5656
/// detail of the `get(exprt)` member function.
57-
exprt get_expr(const smt_termt &descriptor, const typet &type) const;
58-
array_exprt get_expr(const smt_termt &array, const array_typet &type) const;
57+
optionalt<exprt>
58+
get_expr(const smt_termt &descriptor, const typet &type) const;
59+
optionalt<exprt>
60+
get_expr(const smt_termt &array, const array_typet &type) const;
5961

6062
protected:
6163
// Implementation of protected decision_proceduret member function.

0 commit comments

Comments
 (0)