summaryrefslogtreecommitdiff
path: root/src/parser/smt2/smt2.cpp
diff options
context:
space:
mode:
authorAndres Noetzli <andres.noetzli@gmail.com>2020-10-08 22:28:42 -0700
committerGitHub <noreply@github.com>2020-10-08 22:28:42 -0700
commit36addc33791da4b1fbae9fbcec87ac26cfc7a270 (patch)
treec7eee80da27439ed684a12afe22382bae43b4e35 /src/parser/smt2/smt2.cpp
parente5913461e103bd1c7740e88f748524ae66672b53 (diff)
reset-assertions: Remove all non-global symbols in the parser (#5229)
Fixes #5163. When `:global-declarations` is disabled (the default), then `(reset-assertions)` should remove all declared and defined symbols. Before this commit, we would remove the defined function from `SmtEngine` but the parser would not remove it from its symbol table because the symbol was defined at (what it considered) level 0. Level 0, however, is reserved for global symbols that we never want to remove. This commit adds an additional global `pushScope()`/`popScope()`, similar to what we have in `SmtEngine`. As a result, user-defined symbols are now defined at level 1 and get removed from the `SymbolTable` when `(reset-assertions)` is called. The commit also makes sure that symbols defined by the logic are asserted at level 0, so that they are not removed by `(reset-assertions)`. It adds a flag to `defineType` to ignore duplicate definitions because some symbols are defined by multiple logics, which leads to a failing assertion when inserting them both at level 0 in the hashmap of the `SymbolTable`. E.g. strings and integer arithmetic both define `Int`. The commit also fixes existing unit tests that fail with these stricter semantics of `(reset-assertions)`. Signed-off-by: Andres Noetzli <noetzli@amazon.com>
Diffstat (limited to 'src/parser/smt2/smt2.cpp')
-rw-r--r--src/parser/smt2/smt2.cpp41
1 files changed, 19 insertions, 22 deletions
diff --git a/src/parser/smt2/smt2.cpp b/src/parser/smt2/smt2.cpp
index b9b7de149..a226f7cbf 100644
--- a/src/parser/smt2/smt2.cpp
+++ b/src/parser/smt2/smt2.cpp
@@ -37,12 +37,11 @@ Smt2::Smt2(api::Solver* solver, Input* input, bool strictMode, bool parseOnly)
d_logicSet(false),
d_seenSetLogic(false)
{
- if (!strictModeEnabled())
- {
- addCoreSymbols();
- }
+ pushScope(true);
}
+Smt2::~Smt2() { popScope(); }
+
void Smt2::addArithmeticOperators() {
addOperator(api::PLUS, "+");
addOperator(api::MINUS, "-");
@@ -288,9 +287,9 @@ void Smt2::addSepOperators() {
void Smt2::addCoreSymbols()
{
- defineType("Bool", d_solver->getBooleanSort());
- defineVar("true", d_solver->mkTrue());
- defineVar("false", d_solver->mkFalse());
+ defineType("Bool", d_solver->getBooleanSort(), true, true);
+ defineVar("true", d_solver->mkTrue(), true, true);
+ defineVar("false", d_solver->mkFalse(), true, true);
addOperator(api::AND, "and");
addOperator(api::DISTINCT, "distinct");
addOperator(api::EQUAL, "=");
@@ -472,10 +471,7 @@ void Smt2::reset() {
operatorKindMap.clear();
d_lastNamedTerm = std::pair<api::Term, std::string>();
this->Parser::reset();
-
- if( !strictModeEnabled() ) {
- addCoreSymbols();
- }
+ pushScope(true);
}
void Smt2::resetAssertions() {
@@ -483,6 +479,7 @@ void Smt2::resetAssertions() {
while (this->scopeLevel() > 0) {
this->popScope();
}
+ pushScope(true);
}
Smt2::SynthFunFactory::SynthFunFactory(
@@ -604,7 +601,7 @@ Command* Smt2::setLogic(std::string name, bool fromCommand)
if(d_logic.isTheoryEnabled(theory::THEORY_ARITH)) {
if(d_logic.areIntegersUsed()) {
- defineType("Int", d_solver->getIntegerSort());
+ defineType("Int", d_solver->getIntegerSort(), true, true);
addArithmeticOperators();
addOperator(api::INTS_DIVISION, "div");
addOperator(api::INTS_MODULUS, "mod");
@@ -614,7 +611,7 @@ Command* Smt2::setLogic(std::string name, bool fromCommand)
if (d_logic.areRealsUsed())
{
- defineType("Real", d_solver->getRealSort());
+ defineType("Real", d_solver->getRealSort(), true, true);
addArithmeticOperators();
addOperator(api::DIVISION, "/");
if (!strictModeEnabled())
@@ -663,7 +660,7 @@ Command* Smt2::setLogic(std::string name, bool fromCommand)
if(d_logic.isTheoryEnabled(theory::THEORY_DATATYPES)) {
const std::vector<api::Sort> types;
- defineType("Tuple", d_solver->mkTupleSort(types));
+ defineType("Tuple", d_solver->mkTupleSort(types), true, true);
addDatatypesOperators();
}
@@ -708,9 +705,9 @@ Command* Smt2::setLogic(std::string name, bool fromCommand)
addOperator(api::BAG_TO_SET, "bag.to_set");
}
if(d_logic.isTheoryEnabled(theory::THEORY_STRINGS)) {
- defineType("String", d_solver->getStringSort());
- defineType("RegLan", d_solver->getRegExpSort());
- defineType("Int", d_solver->getIntegerSort());
+ defineType("String", d_solver->getStringSort(), true, true);
+ defineType("RegLan", d_solver->getRegExpSort(), true, true);
+ defineType("Int", d_solver->getIntegerSort(), true, true);
if (getLanguage() == language::input::LANG_SMTLIB_V2_6
|| getLanguage() == language::input::LANG_SYGUS_V2)
@@ -735,11 +732,11 @@ Command* Smt2::setLogic(std::string name, bool fromCommand)
}
if (d_logic.isTheoryEnabled(theory::THEORY_FP)) {
- defineType("RoundingMode", d_solver->getRoundingModeSort());
- defineType("Float16", d_solver->mkFloatingPointSort(5, 11));
- defineType("Float32", d_solver->mkFloatingPointSort(8, 24));
- defineType("Float64", d_solver->mkFloatingPointSort(11, 53));
- defineType("Float128", d_solver->mkFloatingPointSort(15, 113));
+ defineType("RoundingMode", d_solver->getRoundingModeSort(), true, true);
+ defineType("Float16", d_solver->mkFloatingPointSort(5, 11), true, true);
+ defineType("Float32", d_solver->mkFloatingPointSort(8, 24), true, true);
+ defineType("Float64", d_solver->mkFloatingPointSort(11, 53), true, true);
+ defineType("Float128", d_solver->mkFloatingPointSort(15, 113), true, true);
defineVar("RNE", d_solver->mkRoundingMode(api::ROUND_NEAREST_TIES_TO_EVEN));
defineVar("roundNearestTiesToEven",
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback