6 #define BOOST_SPIRIT_USE_PHOENIX_V3
7 #include <boost/spirit/include/qi.hpp>
14 std::vector<types::BVTerm> args;
15 if (!
convert(arguments, args)) {
16 errors.
next() <<
"Failed to convert arguments.";
25 std::vector<types::BVTerm> args;
26 if (!
convert(arguments, args)) {
27 errors.
next() <<
"Failed to convert arguments.";
34 template<carl::BVTermType type>
37 if (arguments.size() != 1) {
38 errors.
next() <<
"The operator \"" <<
type <<
"\" expects exactly one argument.";
45 template<carl::BVTermType type>
48 if (arguments.size() != 2) {
49 errors.
next() <<
"The operator \"" <<
type <<
"\" expects exactly two arguments.";
56 template<carl::BVCompareRelation type>
59 if (arguments.size() != 2) {
60 errors.
next() <<
"The operator \"" <<
type <<
"\" expects exactly two arguments.";
67 template<carl::BVTermType type>
70 if (arguments.size() != 1) {
71 errors.
next() <<
"The operator \"" <<
type <<
"\" expects exactly one argument.";
74 if (indices.size() != 1) {
75 errors.
next() <<
"The operator \"" <<
type <<
"\" expects exactly one index.";
84 if (arguments.size() != 1) {
85 errors.
next() <<
"The operator \"extract\" expects exactly one argument.";
88 if (indices.size() != 2) {
89 errors.
next() <<
"The operator \"extract\" expects exactly two indices.";
98 carl::SortManager& sm = carl::SortManager::getInstance();
99 sorts.add(
"BitVec", sm.getInterpreted(carl::VariableType::VT_BOOL));
103 carl::SortManager& sm = carl::SortManager::getInstance();
104 this->
bvSort = sm.addSort(
"BitVec", carl::VariableType::VT_UNINTERPRETED);
105 sm.makeSortIndexable(this->
bvSort, 1, carl::VariableType::VT_BITVECTOR);
150 carl::SortManager& sm = carl::SortManager::getInstance();
151 switch (sm.getType(
sort)) {
152 case carl::VariableType::VT_BITVECTOR: {
154 if ((sm.getIndices(
sort) ==
nullptr) || (sm.getIndices(
sort)->size() != 1)) {
155 errors.
next() <<
"The sort \"" <<
sort <<
"\" should have a single index, being the bit size.";
158 carl::Variable v = carl::fresh_variable(name, carl::VariableType::VT_BITVECTOR);
165 errors.
next() <<
"The requested sort is not a bitvector sort but \"" <<
sort <<
"\".";
180 const std::string& s = identifier.
symbol;
182 if (identifier.
indices ==
nullptr) {
183 errors.
next() <<
"Found a possible bitvector symbol \"" << identifier <<
"\" but no bit size was specified.";
186 if (identifier.
indices->size() != 1) {
187 errors.
next() <<
"Found a possible bitvector symbol \"" << identifier <<
"\" but did not find a single index specifying the bit size.";
190 std::size_t bitsize = identifier.
indices->at(0);
191 carl::BVValue value(bitsize, integer);
202 errors.
next() <<
"Failed to construct ITE, the then-term \"" << thenterm <<
"\" is unsupported.";
206 errors.
next() <<
"Failed to construct ITE, the else-term \"" << elseterm <<
"\" is unsupported.";
209 if (thent.width() != elset.width()) {
210 errors.
next() <<
"Failed to construct ITE, the then-term \"" << thent <<
"\" and the else-term \"" << elset <<
"\" have different widths.";
213 if (ifterm.is_true()) {
result = thent;
return true; }
214 if (ifterm.is_false()) {
result = elset;
return true; }
215 carl::SortManager& sm = carl::SortManager::getInstance();
216 carl::Variable
var = carl::fresh_variable(carl::VariableType::VT_BITVECTOR);
231 std::vector<carl::BVTerm> args;
234 return FormulaT(carl::BVConstraint::create(carl::BVCompareRelation::NEQ, a, b));
243 errors.
next() <<
"The variable is not a bitvector variable.";
248 errors.
next() <<
"Could not convert argument \"" << replacement <<
"\" to a bitvector term.";
258 errors.
next() <<
"The variable is not a bitvector variable.";
261 subject =
carl::BVVariable(carl::fresh_variable(carl::VariableType::VT_BITVECTOR), v.sort());
266 if (identifier.
symbol ==
"=") {
267 if (arguments.size() == 2) {
268 std::vector<types::BVTerm> args;
273 errors.
next() <<
"Operator \"" << identifier <<
"\" expects exactly two arguments, but got " << arguments.size() <<
".";
276 errors.
next() <<
"Invalid operator \"" << identifier <<
"\".";
void sort(T *array, int size, LessThan lt)
carl::BVVariable BVVariable
carl::mpl_variant_of< TermTypes >::type TermType
Variant type for all terms.
carl::BVTerm BVTerm
Typedef for bitvector term.
carl::mpl_variant_of< VariableTypes >::type VariableType
Variant type for all variables.
QuantifierType type(const std::pair< QuantifierType, std::vector< carl::Variable >> &p)
Class to create the formulas for axioms.
carl::Formula< Poly > FormulaT
carl::IntegralType< Rational >::type Integer
Base class for all theories.
FormulaT expandDistinct(const std::vector< T > &values, const Builder &neqBuilder)
bool apply(const std::vector< types::BVTerm > &arguments, types::TermType &result, TheoryError &errors) const
qi::uint_parser< Integer, 10, 1,-1 > number
BitvectorConstantParser()
qi::rule< std::string::const_iterator, Integer()> main
virtual bool apply(const std::vector< types::BVTerm > &arguments, types::TermType &result, TheoryError &errors) const =0
bool operator()(const std::vector< types::TermType > &arguments, types::TermType &result, TheoryError &errors) const
bool apply(const std::vector< types::BVTerm > &arguments, types::TermType &result, TheoryError &errors) const
bool handleITE(const FormulaT &ifterm, const types::TermType &thenterm, const types::TermType &elseterm, types::TermType &result, TheoryError &errors)
Resolve an if-then-else operator.
bool resolveSymbol(const Identifier &identifier, types::TermType &result, TheoryError &errors)
Resolve a symbol that was not declared within the ParserState.
bool handleDistinct(const std::vector< types::TermType > &arguments, types::TermType &result, TheoryError &errors)
Resolve a distinct operator.
conversion::VectorVariantConverter< types::BVTerm > vectorConverter
BitvectorTheory(ParserState *state)
bool refreshVariable(const types::VariableType &var, types::VariableType &subject, TheoryError &errors)
bool declareVariable(const std::string &name, const carl::Sort &sort, types::VariableType &result, TheoryError &errors)
Declare a new variable with the given name and the given sort.
conversion::VariantConverter< types::BVTerm > termConverter
bool instantiate(const types::VariableType &var, const types::TermType &replacement, types::TermType &subject, TheoryError &errors)
Instantiate a variable within a term.
static void addSimpleSorts(qi::symbols< char, carl::Sort > &sorts)
bool functionCall(const Identifier &identifier, const std::vector< types::TermType > &arguments, types::TermType &result, TheoryError &errors)
Resolve another unknown function call.
bool convert(const std::vector< types::TermType > &from, std::vector< T > &to) const
std::vector< std::size_t > * indices
virtual bool apply(const std::vector< std::size_t > &indices, const std::vector< types::BVTerm > &arguments, types::TermType &result, TheoryError &errors) const =0
bool operator()(const std::vector< std::size_t > &indices, const std::vector< types::TermType > &arguments, types::TermType &result, TheoryError &errors) const
bool convert(const std::vector< types::TermType > &from, std::vector< T > &to) const
bool instantiate(V v, const T &repl, types::TermType &subject)
void registerFunction(const std::string &name, const FunctionInstantiator *fi)
FormulasT global_formulas
bool isSymbolFree(const std::string &name, bool output=true)
std::map< std::string, types::VariableType > variables
std::set< types::VariableType > auxiliary_variables
std::vector< smtrat::ModelVariable > artificialVariables
bool apply(const std::vector< std::size_t > &indices, const std::vector< types::BVTerm > &arguments, types::TermType &result, TheoryError &errors) const
bool apply(const std::vector< types::BVTerm > &arguments, types::TermType &result, TheoryError &errors) const
Converts variants to some type using the Converter class.