summaryrefslogtreecommitdiff
path: root/src/expr
diff options
context:
space:
mode:
authorAndres Noetzli <andres.noetzli@gmail.com>2021-05-18 18:27:09 -0700
committerGitHub <noreply@github.com>2021-05-19 01:27:09 +0000
commit4e6e168a5eb578df2bfd12becf7732cbdd23bc3a (patch)
tree1126450ad3e6d5dd453cb64c274ed5798d82588d /src/expr
parent9ee8b184d9e97ae241ff079803b82859ed014dfa (diff)
Improve handling of `:named` attributes (#6549)
Currently, when a :named attribute is used in a binder, the parser complains about an illegal argument. This is because an argument check in the SymbolManager fails. This is not very user friendly. This commit makes the error message clearer for the user: Cannot name a term in a binder (e.g., quantifiers, definitions) To do this, the commit changes the return type for SymbolManager::setExpressionName to include more information that can then be used by the parser to generate an appropriate error message. The commit also changes define-fun to not push/pop the local scope if it has zero arguments because it is semantically equivalent to a define-const, which allows :named terms.
Diffstat (limited to 'src/expr')
-rw-r--r--src/expr/symbol_manager.cpp30
-rw-r--r--src/expr/symbol_manager.h17
2 files changed, 30 insertions, 17 deletions
diff --git a/src/expr/symbol_manager.cpp b/src/expr/symbol_manager.cpp
index c6eb8d08e..8d4870966 100644
--- a/src/expr/symbol_manager.cpp
+++ b/src/expr/symbol_manager.cpp
@@ -48,9 +48,9 @@ class SymbolManager::Implementation
~Implementation() { d_context.pop(); }
/** set expression name */
- bool setExpressionName(api::Term t,
- const std::string& name,
- bool isAssertion = false);
+ NamingResult setExpressionName(api::Term t,
+ const std::string& name,
+ bool isAssertion = false);
/** get expression name */
bool getExpressionName(api::Term t,
std::string& name,
@@ -97,15 +97,17 @@ class SymbolManager::Implementation
CDO<bool> d_hasPushedScope;
};
-bool SymbolManager::Implementation::setExpressionName(api::Term t,
- const std::string& name,
- bool isAssertion)
+NamingResult SymbolManager::Implementation::setExpressionName(
+ api::Term t, const std::string& name, bool isAssertion)
{
Trace("sym-manager") << "SymbolManager: set expression name: " << t << " -> "
<< name << ", isAssertion=" << isAssertion << std::endl;
- // cannot name subexpressions under quantifiers
- PrettyCheckArgument(
- !d_hasPushedScope.get(), name, "cannot name function in a scope");
+ if (d_hasPushedScope.get())
+ {
+ // cannot name subexpressions under binders
+ return NamingResult::ERROR_IN_BINDER;
+ }
+
if (isAssertion)
{
d_namedAsserts.insert(t);
@@ -113,10 +115,10 @@ bool SymbolManager::Implementation::setExpressionName(api::Term t,
if (d_names.find(t) != d_names.end())
{
// already named assertion
- return false;
+ return NamingResult::ERROR_ALREADY_NAMED;
}
d_names[t] = name;
- return true;
+ return NamingResult::SUCCESS;
}
bool SymbolManager::Implementation::getExpressionName(api::Term t,
@@ -269,9 +271,9 @@ SymbolManager::~SymbolManager() {}
SymbolTable* SymbolManager::getSymbolTable() { return &d_symtabAllocated; }
-bool SymbolManager::setExpressionName(api::Term t,
- const std::string& name,
- bool isAssertion)
+NamingResult SymbolManager::setExpressionName(api::Term t,
+ const std::string& name,
+ bool isAssertion)
{
return d_implementation->setExpressionName(t, name, isAssertion);
}
diff --git a/src/expr/symbol_manager.h b/src/expr/symbol_manager.h
index 6cd0a1467..271825e07 100644
--- a/src/expr/symbol_manager.h
+++ b/src/expr/symbol_manager.h
@@ -28,6 +28,17 @@
namespace cvc5 {
+/** Represents the result of a call to `setExpressionName()`. */
+enum class NamingResult
+{
+ /** The expression name was set successfully. */
+ SUCCESS,
+ /** The expression already has a name. */
+ ERROR_ALREADY_NAMED,
+ /** The expression is in a binder. */
+ ERROR_IN_BINDER
+};
+
/**
* Symbol manager, which manages:
* (1) The symbol table used by the parser,
@@ -54,9 +65,9 @@ class CVC5_EXPORT SymbolManager
* @return true if the name was set. This method may return false if t
* already has a name.
*/
- bool setExpressionName(api::Term t,
- const std::string& name,
- bool isAssertion = false);
+ NamingResult setExpressionName(api::Term t,
+ const std::string& name,
+ bool isAssertion = false);
/** Get name for term t
*
* @param t The term
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback