-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add partial string support #327
Changes from 1 commit
1a24094
81ac8e8
c0c66ae
88a943f
c0f950f
1764e7e
8627d1e
bbe5eb7
3334294
4f8cd82
b19ec1d
9a24bc7
b312a48
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -94,6 +94,10 @@ const std::unordered_map<PrimOp, ::cvc5::Kind> primop2kind( | |||||||
{ BV_To_Nat, ::cvc5::BITVECTOR_TO_NAT }, | ||||||||
// Indexed Op | ||||||||
{ Int_To_BV, ::cvc5::INT_TO_BITVECTOR }, | ||||||||
{ StrLt, ::cvc5::STRING_LT }, | ||||||||
{ StrLeq, ::cvc5::STRING_LEQ }, | ||||||||
{ StrLen, ::cvc5::STRING_LENGTH }, | ||||||||
{ StrConcat, ::cvc5::STRING_CONCAT }, | ||||||||
{ Select, ::cvc5::SELECT }, | ||||||||
{ Store, ::cvc5::STORE }, | ||||||||
{ Forall, ::cvc5::FORALL }, | ||||||||
|
@@ -163,7 +167,7 @@ Term Cvc5Solver::make_term(int64_t i, const Sort & sort) const | |||||||
else if (sk == REAL) | ||||||||
{ | ||||||||
c = solver.mkReal(i); | ||||||||
} | ||||||||
} | ||||||||
else if (sk == BV) | ||||||||
{ | ||||||||
// cvc5 uses unsigned integers for mkBitVector | ||||||||
|
@@ -187,6 +191,60 @@ Term Cvc5Solver::make_term(int64_t i, const Sort & sort) const | |||||||
} | ||||||||
} | ||||||||
|
||||||||
Term Cvc5Solver::make_term(const std::string& s, bool useEscSequences, const Sort & sort) const | ||||||||
{ | ||||||||
try | ||||||||
{ | ||||||||
SortKind sk = sort->get_sort_kind(); | ||||||||
::cvc5::Term c; | ||||||||
|
||||||||
if (sk == STRING) | ||||||||
{ | ||||||||
c = solver.mkString(s, useEscSequences); | ||||||||
} | ||||||||
else | ||||||||
{ | ||||||||
std::string msg = "Can't create constant with string and useEscSequences"; | ||||||||
msg += useEscSequences; | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
msg += " for sort "; | ||||||||
msg += sort->to_string(); | ||||||||
throw IncorrectUsageException(msg.c_str()); | ||||||||
} | ||||||||
|
||||||||
return std::make_shared<Cvc5Term>(c); | ||||||||
} | ||||||||
catch (::cvc5::CVC5ApiException & e) | ||||||||
{ | ||||||||
throw IncorrectUsageException(e.what()); | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
Term Cvc5Solver::make_term(const std::wstring& s, const Sort & sort) const | ||||||||
{ | ||||||||
try | ||||||||
{ | ||||||||
SortKind sk = sort->get_sort_kind(); | ||||||||
::cvc5::Term c; | ||||||||
|
||||||||
if (sk == STRING) | ||||||||
{ | ||||||||
c = solver.mkString(s); | ||||||||
} | ||||||||
else | ||||||||
{ | ||||||||
std::string msg = "Can't create constant with wstring for sort "; | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
msg += sort->to_string(); | ||||||||
throw IncorrectUsageException(msg.c_str()); | ||||||||
} | ||||||||
|
||||||||
return std::make_shared<Cvc5Term>(c); | ||||||||
} | ||||||||
catch (::cvc5::CVC5ApiException & e) | ||||||||
{ | ||||||||
throw IncorrectUsageException(e.what()); | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
Term Cvc5Solver::make_term(std::string val, | ||||||||
const Sort & sort, | ||||||||
uint64_t base) const | ||||||||
|
@@ -478,6 +536,10 @@ Sort Cvc5Solver::make_sort(SortKind sk) const | |||||||
{ | ||||||||
return std::make_shared<Cvc5Sort>(solver.getRealSort()); | ||||||||
} | ||||||||
else if (sk == STRING) | ||||||||
{ | ||||||||
return std::make_shared<Cvc5Sort>(solver.getStringSort()); | ||||||||
} | ||||||||
else | ||||||||
{ | ||||||||
std::string msg("Can't create sort with sort constructor "); | ||||||||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -50,6 +50,7 @@ const std::unordered_map<::cvc5::Kind, PrimOp> kind2primop( | |||
{ ::cvc5::NEG, Negate }, | ||||
{ ::cvc5::MULT, Mult }, | ||||
{ ::cvc5::DIVISION, Div }, | ||||
{ ::cvc5::INTS_DIVISION, IntDiv }, | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder -- integer division is already tested, including with cvc5: Line 49 in f2d7d3d
How come we need to add it now? |
||||
{ ::cvc5::LT, Lt }, | ||||
{ ::cvc5::LEQ, Le }, | ||||
{ ::cvc5::GT, Gt }, | ||||
|
@@ -104,6 +105,11 @@ const std::unordered_map<::cvc5::Kind, PrimOp> kind2primop( | |||
{ ::cvc5::BITVECTOR_ROTATE_RIGHT, Rotate_Right }, | ||||
// Conversion | ||||
{ ::cvc5::BITVECTOR_TO_NAT, BV_To_Nat }, | ||||
// String Op | ||||
{ ::cvc5::STRING_LT, StrLt }, | ||||
{ ::cvc5::STRING_LEQ, StrLeq }, | ||||
{ ::cvc5::STRING_LENGTH, StrLen }, | ||||
{ ::cvc5::STRING_CONCAT, StrConcat }, | ||||
// Indexed Op | ||||
{ ::cvc5::INT_TO_BITVECTOR, Int_To_BV }, | ||||
{ ::cvc5::SELECT, Select }, | ||||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -210,6 +210,28 @@ class AbsSmtSolver | |||
*/ | ||||
virtual Term make_term(int64_t i, const Sort & sort) const = 0; | ||||
|
||||
/* Make a string value term | ||||
* @param s is the value | ||||
* @param useEscSequences is the useEscSequences in String constructor | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment is not very clear. What is the string constructor? And what does |
||||
* @param sort the sort to create | ||||
* @return a value term with Sort sort and value s | ||||
*/ | ||||
virtual Term make_term(const std::string& s, bool useEscSequences, const Sort & sort) const{ | ||||
yoni206 marked this conversation as resolved.
Show resolved
Hide resolved
yoni206 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
throw NotImplementedException("Strings not supported for this solver."); | ||||
|
||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
} | ||||
|
||||
/* Make a string value term | ||||
* @param s is the value | ||||
* @param sort the sort to create | ||||
* @return a value term with Sort sort and value s | ||||
*/ | ||||
virtual Term make_term(const std::wstring& s, const Sort & sort) const{ | ||||
yoni206 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
throw NotImplementedException("Strings not supported for this solver."); | ||||
|
||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
} | ||||
|
||||
|
||||
/* Make a bit-vector, int, real or (in the future) string value term | ||||
* @param val the numeric value as a string, or a string value | ||||
* @param sort the sort to create | ||||
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -851,6 +851,36 @@ Term GenericSolver::make_value(int64_t i, const Sort & sort) const | |||||||
} | ||||||||
} | ||||||||
|
||||||||
Term GenericSolver::make_term(const std::string& s, bool useEscSequences, const Sort & sort) const | ||||||||
{ | ||||||||
Term value_term = make_value(s, useEscSequences, sort); | ||||||||
return store_term(value_term); | ||||||||
} | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
Term GenericSolver::make_term(const std::wstring& s, const Sort & sort) const | ||||||||
{ | ||||||||
Term value_term = make_value(s, sort); | ||||||||
return store_term(value_term); | ||||||||
} | ||||||||
|
||||||||
Term GenericSolver::make_value(const std::string& s, bool useEscSequences, const Sort & sort) const | ||||||||
{ | ||||||||
SortKind sk = sort->get_sort_kind(); | ||||||||
assert(sk == STRING); | ||||||||
string repr; | ||||||||
repr = std::to_string(s); | ||||||||
Term term = std::make_shared<GenericTerm>(sort, Op(), TermVec{}, repr); //figure out how to handle useEscSequences | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this figured out yet? :) |
||||||||
return term; | ||||||||
} | ||||||||
Term GenericSolver::make_value(const std::wstring& s, const Sort & sort) const | ||||||||
{ | ||||||||
SortKind sk = sort->get_sort_kind(); | ||||||||
assert(sk == STRING); | ||||||||
string repr; | ||||||||
repr = std::to_string(s); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will that always work? Is it always possible to convert a |
||||||||
Term term = std::make_shared<GenericTerm>(sort, Op(), TermVec{}, repr); | ||||||||
return term; | ||||||||
} | ||||||||
|
||||||||
Term GenericSolver::make_term(const string val, | ||||||||
const Sort & sort, | ||||||||
uint64_t base) const | ||||||||
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -205,6 +205,46 @@ Term LoggingSolver::make_term(int64_t i, const Sort & sort) const | |||||||
return res; | ||||||||
} | ||||||||
|
||||||||
|
||||||||
Term LoggingSolver::make_term(const std::string& s, bool useEscSequences, const Sort & sort) const | ||||||||
{ | ||||||||
shared_ptr<LoggingSort> lsort = static_pointer_cast<LoggingSort>(sort); | ||||||||
Term wrapped_res = wrapped_solver->make_term(s, useEscSequences, lsort->wrapped_sort); | ||||||||
Term res = std::make_shared<LoggingTerm>( | ||||||||
wrapped_res, sort, Op(), TermVec{}, next_term_id); | ||||||||
|
||||||||
// check hash table | ||||||||
// lookup modifies term in place and returns true if it's a known term | ||||||||
// i.e. returns existing term and destroying the unnecessary new one | ||||||||
if (!hashtable->lookup(res)) | ||||||||
{ | ||||||||
// this is the first time this term was created | ||||||||
hashtable->insert(res); | ||||||||
next_term_id++; | ||||||||
} | ||||||||
|
||||||||
return res; | ||||||||
} | ||||||||
Term LoggingSolver::make_term(const std::wstring& s, const Sort & sort) const{ | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
shared_ptr<LoggingSort> lsort = static_pointer_cast<LoggingSort>(sort); | ||||||||
Term wrapped_res = wrapped_solver->make_term(s, lsort->wrapped_sort); | ||||||||
Term res = std::make_shared<LoggingTerm>( | ||||||||
wrapped_res, sort, Op(), TermVec{}, next_term_id); | ||||||||
|
||||||||
// check hash table | ||||||||
// lookup modifies term in place and returns true if it's a known term | ||||||||
// i.e. returns existing term and destroying the unnecessary new one | ||||||||
if (!hashtable->lookup(res)) | ||||||||
{ | ||||||||
// this is the first time this term was created | ||||||||
hashtable->insert(res); | ||||||||
next_term_id++; | ||||||||
} | ||||||||
|
||||||||
return res; | ||||||||
} | ||||||||
|
||||||||
|
||||||||
Term LoggingSolver::make_term(const string name, | ||||||||
const Sort & sort, | ||||||||
uint64_t base) const | ||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure this is what we want to do.
If the directory already exists, then this would probably mean that
cvc5
is already built in it, no?