diff options
author | Aina Niemetz <aina.niemetz@gmail.com> | 2021-03-10 13:28:58 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-10 21:28:58 +0000 |
commit | c81140e9ab5db8bc95eb15145641be9d909d0618 (patch) | |
tree | 991c424872f4b23a06b81dab9db7b8bf8aa30a7b /src/expr | |
parent | bd52deb7434b1b08a122db4513972644c11fc4aa (diff) |
Move ExprManager::isNAryKind to NodeManager. (#6107)
This also renames metakind::getLowerBoundForKind and
metakind::getUpperBoundForKind for consistency.
Note that the NodeManager class needs to be reordered to comply to our
style guidelines. This PR does not reorder but introduces a public block
at the top (where the rest of the public interface of the class should
go eventually).
Diffstat (limited to 'src/expr')
-rw-r--r-- | src/expr/expr_manager_template.cpp | 4 | ||||
-rw-r--r-- | src/expr/metakind_template.cpp | 9 | ||||
-rw-r--r-- | src/expr/metakind_template.h | 6 | ||||
-rw-r--r-- | src/expr/node_builder.h | 16 | ||||
-rw-r--r-- | src/expr/node_manager.cpp | 10 | ||||
-rw-r--r-- | src/expr/node_manager.h | 9 |
6 files changed, 36 insertions, 18 deletions
diff --git a/src/expr/expr_manager_template.cpp b/src/expr/expr_manager_template.cpp index c4a8871fe..414d8a611 100644 --- a/src/expr/expr_manager_template.cpp +++ b/src/expr/expr_manager_template.cpp @@ -812,11 +812,11 @@ Expr ExprManager::mkChain(Kind kind, const std::vector<Expr>& children) } unsigned ExprManager::minArity(Kind kind) { - return metakind::getLowerBoundForKind(kind); + return metakind::getMinArityForKind(kind); } unsigned ExprManager::maxArity(Kind kind) { - return metakind::getUpperBoundForKind(kind); + return metakind::getMaxArityForKind(kind); } bool ExprManager::isNAryKind(Kind fun) diff --git a/src/expr/metakind_template.cpp b/src/expr/metakind_template.cpp index 96e06156d..6e76c0da3 100644 --- a/src/expr/metakind_template.cpp +++ b/src/expr/metakind_template.cpp @@ -147,7 +147,8 @@ ${metakind_constDeleters} // re-enable the strict-aliasing warning # pragma GCC diagnostic warning "-Wstrict-aliasing" -unsigned getLowerBoundForKind(::CVC4::Kind k) { +uint32_t getMinArityForKind(::CVC4::Kind k) +{ static const unsigned lbs[] = { 0, /* NULL_EXPR */ ${metakind_lbchildren} @@ -158,7 +159,8 @@ ${metakind_lbchildren} return lbs[k]; } -unsigned getUpperBoundForKind(::CVC4::Kind k) { +uint32_t getMaxArityForKind(::CVC4::Kind k) +{ static const unsigned ubs[] = { 0, /* NULL_EXPR */ ${metakind_ubchildren} @@ -168,8 +170,7 @@ ${metakind_ubchildren} return ubs[k]; } - -}/* CVC4::metakind namespace */ +} // namespace metakind /** * Map a kind of the operator to the kind of the enclosing expression. For diff --git a/src/expr/metakind_template.h b/src/expr/metakind_template.h index 4e47d4230..42b7da248 100644 --- a/src/expr/metakind_template.h +++ b/src/expr/metakind_template.h @@ -187,8 +187,10 @@ struct NodeValueConstPrinter { */ void deleteNodeValueConstant(::CVC4::expr::NodeValue* nv); -unsigned getLowerBoundForKind(::CVC4::Kind k); -unsigned getUpperBoundForKind(::CVC4::Kind k); +/** Return the minimum arity of the given kind. */ +uint32_t getMinArityForKind(::CVC4::Kind k); +/** Return the maximum arity of the given kind. */ +uint32_t getMaxArityForKind(::CVC4::Kind k); }/* CVC4::kind::metakind namespace */ diff --git a/src/expr/node_builder.h b/src/expr/node_builder.h index 2f4640668..91b378c5f 100644 --- a/src/expr/node_builder.h +++ b/src/expr/node_builder.h @@ -957,15 +957,15 @@ expr::NodeValue* NodeBuilder<nchild_thresh>::constructNV() { // check that there are the right # of children for this kind Assert(getMetaKind() != kind::metakind::CONSTANT) << "Cannot make Nodes with NodeBuilder that have CONSTANT-kinded kinds"; - Assert(getNumChildren() >= kind::metakind::getLowerBoundForKind(getKind())) + Assert(getNumChildren() >= kind::metakind::getMinArityForKind(getKind())) << "Nodes with kind " << getKind() << " must have at least " - << kind::metakind::getLowerBoundForKind(getKind()) + << kind::metakind::getMinArityForKind(getKind()) << " children (the one under " "construction has " << getNumChildren() << ")"; - Assert(getNumChildren() <= kind::metakind::getUpperBoundForKind(getKind())) + Assert(getNumChildren() <= kind::metakind::getMaxArityForKind(getKind())) << "Nodes with kind " << getKind() << " must have at most " - << kind::metakind::getUpperBoundForKind(getKind()) + << kind::metakind::getMaxArityForKind(getKind()) << " children (the one under " "construction has " << getNumChildren() << ")"; @@ -1132,15 +1132,15 @@ expr::NodeValue* NodeBuilder<nchild_thresh>::constructNV() const { // check that there are the right # of children for this kind Assert(getMetaKind() != kind::metakind::CONSTANT) << "Cannot make Nodes with NodeBuilder that have CONSTANT-kinded kinds"; - Assert(getNumChildren() >= kind::metakind::getLowerBoundForKind(getKind())) + Assert(getNumChildren() >= kind::metakind::getMinArityForKind(getKind())) << "Nodes with kind " << getKind() << " must have at least " - << kind::metakind::getLowerBoundForKind(getKind()) + << kind::metakind::getMinArityForKind(getKind()) << " children (the one under " "construction has " << getNumChildren() << ")"; - Assert(getNumChildren() <= kind::metakind::getUpperBoundForKind(getKind())) + Assert(getNumChildren() <= kind::metakind::getMaxArityForKind(getKind())) << "Nodes with kind " << getKind() << " must have at most " - << kind::metakind::getUpperBoundForKind(getKind()) + << kind::metakind::getMaxArityForKind(getKind()) << " children (the one under " "construction has " << getNumChildren() << ")"; diff --git a/src/expr/node_manager.cpp b/src/expr/node_manager.cpp index 5eb01ecbb..12fc99eaa 100644 --- a/src/expr/node_manager.cpp +++ b/src/expr/node_manager.cpp @@ -27,6 +27,7 @@ #include "expr/bound_var_manager.h" #include "expr/dtype.h" #include "expr/dtype_cons.h" +#include "expr/metakind.h" #include "expr/node_manager_attributes.h" #include "expr/skolem_manager.h" #include "expr/type_checker.h" @@ -108,6 +109,11 @@ NodeManager::NodeManager(ExprManager* exprManager) init(); } +bool NodeManager::isNAryKind(Kind k) +{ + return kind::metakind::getMaxArityForKind(k) == expr::NodeValue::MAX_CHILDREN; +} + TypeNode NodeManager::booleanType() { return mkTypeConst<TypeConstant>(BOOLEAN_TYPE); @@ -965,7 +971,7 @@ Node NodeManager::mkAssociative(Kind kind, const std::vector<Node>& children) { AlwaysAssert(kind::isAssociative(kind)) << "Illegal kind in mkAssociative"; - const unsigned int max = kind::metakind::getUpperBoundForKind(kind); + const unsigned int max = kind::metakind::getMaxArityForKind(kind); size_t numChildren = children.size(); /* If the number of children is within bounds, then there's nothing to do. */ @@ -973,7 +979,7 @@ Node NodeManager::mkAssociative(Kind kind, const std::vector<Node>& children) { return mkNode(kind, children); } - const unsigned int min = kind::metakind::getLowerBoundForKind(kind); + const unsigned int min = kind::metakind::getMinArityForKind(kind); std::vector<Node>::const_iterator it = children.begin(); std::vector<Node>::const_iterator end = children.end(); diff --git a/src/expr/node_manager.h b/src/expr/node_manager.h index 7eba1b2ea..fc58410d1 100644 --- a/src/expr/node_manager.h +++ b/src/expr/node_manager.h @@ -98,6 +98,15 @@ class NodeManager friend class NodeBuilder; friend class NodeManagerScope; + public: + /** + * Return true if given kind is n-ary. The test is based on n-ary kinds + * having their maximal arity as the maximal possible number of children + * of a node. + */ + static bool isNAryKind(Kind k); + + private: /** Predicate for use with STL algorithms */ struct NodeValueReferenceCountNonZero { bool operator()(expr::NodeValue* nv) { return nv->d_rc > 0; } |