Skip to content

Commit aab0b9b

Browse files
author
Daniel Kroening
authored
Merge pull request #3547 from diffblue/smt2_concat
smt2: concat
2 parents 01abfb2 + 24883f0 commit aab0b9b

File tree

3 files changed

+36
-21
lines changed

3 files changed

+36
-21
lines changed

scripts/delete_failing_smt2_solver_tests

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,6 @@ rm equality_through_struct_containing_arrays2/test.desc
8787
rm equality_through_union1/test.desc
8888
rm equality_through_union2/test.desc
8989
rm equality_through_union3/test.desc
90-
rm gcc_bswap1/test.desc
91-
rm gcc_vector1/test.desc
9290
rm graphml_witness1/test.desc
9391
rm integer-assignments1/test.desc
9492
rm memory_allocation1/test.desc

src/solvers/smt2/smt2_parser.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ Author: Daniel Kroening, [email protected]
1111
#include "smt2_format.h"
1212

1313
#include <util/arith_tools.h>
14+
#include <util/range.h>
15+
16+
#include <numeric>
1417

1518
smt2_parsert::tokent smt2_parsert::next_token()
1619
{
@@ -612,15 +615,17 @@ exprt smt2_parsert::function_application()
612615
}
613616
else if(id=="concat")
614617
{
615-
if(op.size()!=2)
616-
throw error("concat takes two operands");
618+
// add the widths
619+
auto op_width = make_range(op).map([](const exprt &o) {
620+
return to_unsignedbv_type(o.type()).get_width();
621+
});
617622

618-
auto width0=to_unsignedbv_type(op[0].type()).get_width();
619-
auto width1=to_unsignedbv_type(op[1].type()).get_width();
623+
const std::size_t total_width =
624+
std::accumulate(op_width.begin(), op_width.end(), 0);
620625

621-
unsignedbv_typet t(width0+width1);
626+
const unsignedbv_typet t(total_width);
622627

623-
return binary_exprt(op[0], ID_concatenation, op[1], t);
628+
return concatenation_exprt(std::move(op), t);
624629
}
625630
else if(id=="distinct")
626631
{

src/util/std_expr.h

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -973,22 +973,32 @@ template<> inline bool can_cast_expr<binary_relation_exprt>(const exprt &base)
973973
class multi_ary_exprt:public exprt
974974
{
975975
public:
976-
DEPRECATED("use multi_ary_exprt(id, type) instead")
976+
DEPRECATED("use multi_ary_exprt(id, op, type) instead")
977977
multi_ary_exprt()
978978
{
979979
}
980980

981-
DEPRECATED("use multi_ary_exprt(id, type) instead")
981+
DEPRECATED("use multi_ary_exprt(id, op, type) instead")
982982
explicit multi_ary_exprt(const irep_idt &_id):exprt(_id)
983983
{
984984
}
985985

986+
DEPRECATED("use multi_ary_exprt(id, op, type) instead")
986987
multi_ary_exprt(
987988
const irep_idt &_id,
988989
const typet &_type):exprt(_id, _type)
989990
{
990991
}
991992

993+
multi_ary_exprt(
994+
const irep_idt &_id,
995+
operandst &&_operands,
996+
const typet &_type)
997+
: exprt(_id, _type)
998+
{
999+
operands() = std::move(_operands);
1000+
}
1001+
9921002
multi_ary_exprt(
9931003
const exprt &_lhs,
9941004
const irep_idt &_id,
@@ -4531,31 +4541,33 @@ inline void validate_expr(const function_application_exprt &value)
45314541
validate_operands(value, 2, "Function application must have two operands");
45324542
}
45334543

4534-
45354544
/// \brief Concatenation of bit-vector operands
45364545
///
45374546
/// This expression takes any number of operands
4538-
/// (a restriction to make this binary will happen in the future).
4539-
/// The ordering of the operands is the same as in the _new_ SMT 1.x standard,
4547+
/// The ordering of the operands is the same as in the SMT-LIB 2 standard,
45404548
/// i.e., most-significant operands come first.
4541-
class concatenation_exprt:public exprt
4549+
class concatenation_exprt : public multi_ary_exprt
45424550
{
45434551
public:
4544-
DEPRECATED("use concatenation_exprt(op0, op1, type) instead")
4545-
concatenation_exprt():exprt(ID_concatenation)
4552+
DEPRECATED("use concatenation_exprt(op, type) instead")
4553+
concatenation_exprt() : multi_ary_exprt(ID_concatenation)
45464554
{
45474555
}
45484556

4549-
DEPRECATED("use concatenation_exprt(op0, op1, type) instead")
4550-
explicit concatenation_exprt(const typet &_type):
4551-
exprt(ID_concatenation, _type)
4557+
DEPRECATED("use concatenation_exprt(op, type) instead")
4558+
explicit concatenation_exprt(const typet &_type)
4559+
: multi_ary_exprt(ID_concatenation, _type)
45524560
{
45534561
}
45544562

45554563
concatenation_exprt(const exprt &_op0, const exprt &_op1, const typet &_type)
4556-
: exprt(ID_concatenation, _type)
4564+
: multi_ary_exprt(_op0, ID_concatenation, _op1, _type)
4565+
{
4566+
}
4567+
4568+
concatenation_exprt(operandst &&_operands, const typet &_type)
4569+
: multi_ary_exprt(ID_concatenation, std::move(_operands), _type)
45574570
{
4558-
add_to_operands(_op0, _op1);
45594571
}
45604572
};
45614573

0 commit comments

Comments
 (0)