From c49e8a66f30413adc802c7200ec02c68e33feae6 Mon Sep 17 00:00:00 2001 From: Morgan Deters Date: Thu, 1 Apr 2010 06:59:18 +0000 Subject: * 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. --- src/expr/expr_manager_template.cpp | 45 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'src/expr/expr_manager_template.cpp') 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& 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 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; -- cgit v1.2.3