diff options
author | Morgan Deters <mdeters@gmail.com> | 2010-04-01 06:59:18 +0000 |
---|---|---|
committer | Morgan Deters <mdeters@gmail.com> | 2010-04-01 06:59:18 +0000 |
commit | c49e8a66f30413adc802c7200ec02c68e33feae6 (patch) | |
tree | bab593196b862b2e22f5cc07cf3d9f8a97e86e16 /src/expr/expr_manager_template.cpp | |
parent | f208251e33814430decb89c2c9001b5a675402f9 (diff) |
* Minor code formatting stuff in src/expr/type.{h,cpp}. Concluded
Type code review and closed bug #25.
* Do assertions on Expr creation (public library interface) even when
assertions are off. Also a similar check for proper kind (in public
interface) when Expr::getConst<>() is called. This fixes a unit
test that was failing in production builds (an exception wasn't
thrown but should have been).
* kind::XOR must have exactly 2 arguments, not 2-or-more.
Diffstat (limited to 'src/expr/expr_manager_template.cpp')
-rw-r--r-- | src/expr/expr_manager_template.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/expr/expr_manager_template.cpp b/src/expr/expr_manager_template.cpp index 2e25b4574..a2c90937b 100644 --- a/src/expr/expr_manager_template.cpp +++ b/src/expr/expr_manager_template.cpp @@ -57,16 +57,34 @@ KindType* ExprManager::kindType() const { } Expr ExprManager::mkExpr(Kind kind) { + const unsigned n = 0; + CheckArgument(n >= minArity(kind) && n <= maxArity(kind), kind, + "Exprs with kind %s must have at least %u children and " + "at most %u children (the one under construction has %u)", + kind::kindToString(kind).c_str(), + minArity(kind), maxArity(kind), n); NodeManagerScope nms(d_nodeManager); return Expr(this, new Node(d_nodeManager->mkNode(kind))); } Expr ExprManager::mkExpr(Kind kind, const Expr& child1) { + const unsigned n = 1; + CheckArgument(n >= minArity(kind) && n <= maxArity(kind), kind, + "Exprs with kind %s must have at least %u children and " + "at most %u children (the one under construction has %u)", + kind::kindToString(kind).c_str(), + minArity(kind), maxArity(kind), n); NodeManagerScope nms(d_nodeManager); return Expr(this, new Node(d_nodeManager->mkNode(kind, child1.getNode()))); } Expr ExprManager::mkExpr(Kind kind, const Expr& child1, const Expr& child2) { + const unsigned n = 2; + CheckArgument(n >= minArity(kind) && n <= maxArity(kind), kind, + "Exprs with kind %s must have at least %u children and " + "at most %u children (the one under construction has %u)", + kind::kindToString(kind).c_str(), + minArity(kind), maxArity(kind), n); NodeManagerScope nms(d_nodeManager); return Expr(this, new Node(d_nodeManager->mkNode(kind, child1.getNode(), child2.getNode()))); @@ -74,6 +92,12 @@ Expr ExprManager::mkExpr(Kind kind, const Expr& child1, const Expr& child2) { Expr ExprManager::mkExpr(Kind kind, const Expr& child1, const Expr& child2, const Expr& child3) { + const unsigned n = 3; + CheckArgument(n >= minArity(kind) && n <= maxArity(kind), kind, + "Exprs with kind %s must have at least %u children and " + "at most %u children (the one under construction has %u)", + kind::kindToString(kind).c_str(), + minArity(kind), maxArity(kind), n); NodeManagerScope nms(d_nodeManager); return Expr(this, new Node(d_nodeManager->mkNode(kind, child1.getNode(), child2.getNode(), child3.getNode()))); @@ -81,6 +105,12 @@ Expr ExprManager::mkExpr(Kind kind, const Expr& child1, const Expr& child2, Expr ExprManager::mkExpr(Kind kind, const Expr& child1, const Expr& child2, const Expr& child3, const Expr& child4) { + const unsigned n = 4; + CheckArgument(n >= minArity(kind) && n <= maxArity(kind), kind, + "Exprs with kind %s must have at least %u children and " + "at most %u children (the one under construction has %u)", + kind::kindToString(kind).c_str(), + minArity(kind), maxArity(kind), n); NodeManagerScope nms(d_nodeManager); return Expr(this, new Node(d_nodeManager->mkNode(kind, child1.getNode(), child2.getNode(), child3.getNode(), @@ -90,6 +120,12 @@ Expr ExprManager::mkExpr(Kind kind, const Expr& child1, const Expr& child2, Expr ExprManager::mkExpr(Kind kind, const Expr& child1, const Expr& child2, const Expr& child3, const Expr& child4, const Expr& child5) { + const unsigned n = 5; + CheckArgument(n >= minArity(kind) && n <= maxArity(kind), kind, + "Exprs with kind %s must have at least %u children and " + "at most %u children (the one under construction has %u)", + kind::kindToString(kind).c_str(), + minArity(kind), maxArity(kind), n); NodeManagerScope nms(d_nodeManager); return Expr(this, new Node(d_nodeManager->mkNode(kind, child1.getNode(), child2.getNode(), child3.getNode(), @@ -97,6 +133,13 @@ Expr ExprManager::mkExpr(Kind kind, const Expr& child1, const Expr& child2, } Expr ExprManager::mkExpr(Kind kind, const vector<Expr>& children) { + const unsigned n = children.size(); + CheckArgument(n >= minArity(kind) && n <= maxArity(kind), kind, + "Exprs with kind %s must have at least %u children and " + "at most %u children (the one under construction has %u)", + kind::kindToString(kind).c_str(), + minArity(kind), maxArity(kind), n); + NodeManagerScope nms(d_nodeManager); vector<Node> nodes; @@ -171,6 +214,7 @@ unsigned ExprManager::minArity(Kind kind) { case IFF: case IMPLIES: case PLUS: + case MULT: case XOR: return 2; @@ -207,6 +251,7 @@ unsigned ExprManager::maxArity(Kind kind) { case APPLY_UF: case DISTINCT: case PLUS: + case MULT: case OR: return UINT_MAX; |