Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions regression/smt2_solver/arrays/as_const1.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CORE
as_const1.smt2

^EXIT=0$
^SIGNAL=0$
^unsat$
--
8 changes: 8 additions & 0 deletions regression/smt2_solver/arrays/as_const1.smt2
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
; an array consisting of all #x10
(declare-const array (Array (_ BitVec 16) (_ BitVec 8)))
(assert (= array ((as const (Array (_ BitVec 16) (_ BitVec 8))) #x10)))

(declare-const index (_ BitVec 16))
(assert (not (= #x10 (select array index))))

(check-sat)
8 changes: 8 additions & 0 deletions regression/smt2_solver/arrays/as_const2.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
as_const2.smt2

^EXIT=0$
^SIGNAL=0$
^sat$
^\(\(sample \(_ bv16 8\)\)\)$
--
9 changes: 9 additions & 0 deletions regression/smt2_solver/arrays/as_const2.smt2
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
; an array consisting of all #x10
(declare-const array (Array (_ BitVec 16) (_ BitVec 8)))
(assert (= array ((as const (Array (_ BitVec 16) (_ BitVec 8))) #x10)))

(declare-const sample (_ BitVec 8))
(assert (= sample (select array #x0000)))

(check-sat)
(get-value (sample))
34 changes: 34 additions & 0 deletions src/solvers/smt2/smt2_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,40 @@ exprt smt2_parsert::function_application()
<< smt2_tokenizer.get_buffer() << '\'';
}
}
else if(smt2_tokenizer.get_buffer() == "as")
{
// This is an extension understood by Z3 and CVC4.
if(
smt2_tokenizer.peek() == smt2_tokenizert::SYMBOL &&
smt2_tokenizer.get_buffer() == "const")
{
next_token(); // eat the "const"
auto sort = this->sort();

if(sort.id() != ID_array)
{
throw error()
<< "unexpected 'as const' expression expects array type";
}

const auto &array_sort = to_array_type(sort);

if(smt2_tokenizer.next_token() != smt2_tokenizert::CLOSE)
throw error() << "expecting ')' after sort in 'as const'";

auto value = expression();

if(value.type() != array_sort.subtype())
throw error() << "unexpected 'as const' with wrong element type";

if(smt2_tokenizer.next_token() != smt2_tokenizert::CLOSE)
throw error() << "expecting ')' at the end of 'as const'";

return array_of_exprt(value, array_sort);
}
else
throw error() << "unexpected 'as' expression";
}
else
{
// just double parentheses
Expand Down