-
Notifications
You must be signed in to change notification settings - Fork 274
Add bit vector extract operation support to incremental SMT2 solving #6654
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
Merged
thomasspriggs
merged 8 commits into
diffblue:develop
from
thomasspriggs:tas/smt_bv_extract
Feb 11, 2022
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
21a0a85
Mark `smt_function_application_termt::factoryt` as `noexcept`
thomasspriggs d1c5bf7
Add indexed identifier support to `smt_identifier_termt`
thomasspriggs d90f98c
Implement printing for indexed identifiers
thomasspriggs 79618ce
Add indexed identifier support to smt function `factoryt`
thomasspriggs b4862bd
Add SMT bit vector theory extract function
thomasspriggs f520e9e
Reorder includes in smt_to_smt2_string unit test
thomasspriggs aac7993
Test printing of bit vector extract
thomasspriggs 8edd58d
Disallow construction of `smt_symbol_indext` with empty string
thomasspriggs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Author: Diffblue Ltd. | ||
|
||
#include "smt_index.h" | ||
|
||
// Define the irep_idts for kinds of index. | ||
const irep_idt ID_smt_numeral_index{"smt_numeral_index"}; | ||
const irep_idt ID_smt_symbol_index{"smt_symbol_index"}; | ||
|
||
bool smt_indext::operator==(const smt_indext &other) const | ||
{ | ||
return irept::operator==(other); | ||
} | ||
|
||
bool smt_indext::operator!=(const smt_indext &other) const | ||
{ | ||
return !(*this == other); | ||
} | ||
|
||
template <> | ||
const smt_numeral_indext *smt_indext::cast<smt_numeral_indext>() const & | ||
{ | ||
return id() == ID_smt_numeral_index | ||
? static_cast<const smt_numeral_indext *>(this) | ||
: nullptr; | ||
} | ||
|
||
template <> | ||
const smt_symbol_indext *smt_indext::cast<smt_symbol_indext>() const & | ||
{ | ||
return id() == ID_smt_symbol_index | ||
? static_cast<const smt_symbol_indext *>(this) | ||
: nullptr; | ||
} | ||
|
||
void smt_indext::accept(smt_index_const_downcast_visitort &visitor) const | ||
{ | ||
if(const auto numeral = this->cast<smt_numeral_indext>()) | ||
return visitor.visit(*numeral); | ||
if(const auto symbol = this->cast<smt_symbol_indext>()) | ||
return visitor.visit(*symbol); | ||
UNREACHABLE; | ||
} | ||
|
||
smt_numeral_indext::smt_numeral_indext(std::size_t value) | ||
: smt_indext{ID_smt_numeral_index} | ||
{ | ||
set_size_t(ID_value, value); | ||
} | ||
|
||
std::size_t smt_numeral_indext::value() const | ||
{ | ||
return get_size_t(ID_value); | ||
} | ||
|
||
smt_symbol_indext::smt_symbol_indext(irep_idt identifier) | ||
: smt_indext{ID_smt_symbol_index} | ||
{ | ||
PRECONDITION(!identifier.empty()); | ||
set(ID_identifier, identifier); | ||
} | ||
|
||
irep_idt smt_symbol_indext::identifier() const | ||
{ | ||
return get(ID_identifier); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// Author: Diffblue Ltd. | ||
|
||
#ifndef CPROVER_SOLVERS_SMT2_INCREMENTAL_SMT_INDEX_H | ||
#define CPROVER_SOLVERS_SMT2_INCREMENTAL_SMT_INDEX_H | ||
|
||
#include <util/irep.h> | ||
|
||
class smt_index_const_downcast_visitort; | ||
|
||
/// \brief | ||
/// For implementation of indexed identifiers. See SMT-LIB Standard Version 2.6 | ||
/// section 3.3. | ||
class smt_indext : protected irept | ||
{ | ||
public: | ||
// smt_indext does not support the notion of an empty / null state. Use | ||
// optionalt<smt_indext> instead if an empty index is required. | ||
smt_indext() = delete; | ||
|
||
using irept::pretty; | ||
|
||
bool operator==(const smt_indext &) const; | ||
bool operator!=(const smt_indext &) const; | ||
|
||
template <typename sub_classt> | ||
const sub_classt *cast() const &; | ||
|
||
void accept(smt_index_const_downcast_visitort &) const; | ||
|
||
/// \brief Class for adding the ability to up and down cast smt_indext to and | ||
/// from irept. These casts are required by other irept derived classes in | ||
/// order to store instances of smt_termt inside them. | ||
/// \tparam derivedt The type of class which derives from this class and from | ||
/// irept. | ||
template <typename derivedt> | ||
class storert | ||
{ | ||
protected: | ||
storert(); | ||
static irept upcast(smt_indext index); | ||
static const smt_indext &downcast(const irept &); | ||
}; | ||
|
||
protected: | ||
using irept::irept; | ||
}; | ||
|
||
template <typename derivedt> | ||
smt_indext::storert<derivedt>::storert() | ||
{ | ||
static_assert( | ||
std::is_base_of<irept, derivedt>::value && | ||
std::is_base_of<storert<derivedt>, derivedt>::value, | ||
"Only irept based classes need to upcast smt_sortt to store it."); | ||
} | ||
|
||
template <typename derivedt> | ||
irept smt_indext::storert<derivedt>::upcast(smt_indext index) | ||
{ | ||
return static_cast<irept &&>(std::move(index)); | ||
} | ||
|
||
template <typename derivedt> | ||
const smt_indext &smt_indext::storert<derivedt>::downcast(const irept &irep) | ||
{ | ||
return static_cast<const smt_indext &>(irep); | ||
} | ||
|
||
class smt_numeral_indext : public smt_indext | ||
{ | ||
public: | ||
explicit smt_numeral_indext(std::size_t value); | ||
std::size_t value() const; | ||
}; | ||
|
||
class smt_symbol_indext : public smt_indext | ||
{ | ||
public: | ||
explicit smt_symbol_indext(irep_idt identifier); | ||
irep_idt identifier() const; | ||
}; | ||
|
||
class smt_index_const_downcast_visitort | ||
{ | ||
public: | ||
virtual void visit(const smt_numeral_indext &) = 0; | ||
virtual void visit(const smt_symbol_indext &) = 0; | ||
}; | ||
|
||
#endif // CPROVER_SOLVERS_SMT2_INCREMENTAL_SMT_INDEX_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.