inline const_iterator begin() const {
Assert(!isUsed(), "NodeBuilder is one-shot only; "
"attempt to access it after conversion");
- CheckArgument(getKind() != kind::UNDEFINED_KIND,
- "Iterators over NodeBuilder<> are undefined "
- "until a Kind is set");
+ Assert(getKind() != kind::UNDEFINED_KIND,
+ "Iterators over NodeBuilder<> are undefined "
+ "until a Kind is set");
return d_nv->begin< NodeTemplate<true> >();
}
inline const_iterator end() const {
Assert(!isUsed(), "NodeBuilder is one-shot only; "
"attempt to access it after conversion");
- CheckArgument(getKind() != kind::UNDEFINED_KIND,
- "Iterators over NodeBuilder<> are undefined "
- "until a Kind is set");
+ Assert(getKind() != kind::UNDEFINED_KIND,
+ "Iterators over NodeBuilder<> are undefined "
+ "until a Kind is set");
return d_nv->end< NodeTemplate<true> >();
}
inline kind::MetaKind getMetaKind() const {
Assert(!isUsed(), "NodeBuilder is one-shot only; "
"attempt to access it after conversion");
- CheckArgument(getKind() != kind::UNDEFINED_KIND,
- "The metakind of a NodeBuilder<> is undefined "
- "until a Kind is set");
+ Assert(getKind() != kind::UNDEFINED_KIND,
+ "The metakind of a NodeBuilder<> is undefined "
+ "until a Kind is set");
return d_nv->getMetaKind();
}
inline unsigned getNumChildren() const {
Assert(!isUsed(), "NodeBuilder is one-shot only; "
"attempt to access it after conversion");
- CheckArgument(getKind() != kind::UNDEFINED_KIND,
- "The number of children of a NodeBuilder<> is undefined "
- "until a Kind is set");
+ Assert(getKind() != kind::UNDEFINED_KIND,
+ "The number of children of a NodeBuilder<> is undefined "
+ "until a Kind is set");
return d_nv->getNumChildren();
}
- /** Access to children of this Node-under-construction. */
+ /**
+ * Access to the operator of this Node-under-construction. Only
+ * allowed if this NodeBuilder is unused, and has a defined kind
+ * that is of PARAMETERIZED metakind.
+ */
+ inline Node getOperator() const {
+ Assert(!isUsed(), "NodeBuilder is one-shot only; "
+ "attempt to access it after conversion");
+ Assert(getKind() != kind::UNDEFINED_KIND,
+ "NodeBuilder<> operator access is not permitted "
+ "until a Kind is set");
+ Assert(getMetaKind() == kind::metakind::PARAMETERIZED,
+ "NodeBuilder<> operator access is only permitted "
+ "on parameterized kinds, not `%s'",
+ kind::kindToString(getKind()).c_str());
+ return Node(d_nv->getOperator());
+ }
+
+ /**
+ * Access to children of this Node-under-construction. Only allowed
+ * if this NodeBuilder is unused and has a defined kind.
+ */
inline Node getChild(int i) const {
Assert(!isUsed(), "NodeBuilder is one-shot only; "
"attempt to access it after conversion");
- CheckArgument(getKind() != kind::UNDEFINED_KIND,
- "NodeBuilder<> child access is not permitted "
- "until a Kind is set");
+ Assert(getKind() != kind::UNDEFINED_KIND,
+ "NodeBuilder<> child access is not permitted "
+ "until a Kind is set");
Assert(i >= 0 && unsigned(i) < d_nv->getNumChildren(),
"index out of range for NodeBuilder::getChild()");
return Node(d_nv->getChild(i));
/* default size tests */
NodeBuilder<> def;
TS_ASSERT_EQUALS(def.getKind(), UNDEFINED_KIND);
- TS_ASSERT_THROWS(def.getNumChildren(), IllegalArgumentException);
- TS_ASSERT_THROWS(def.begin(), IllegalArgumentException);
- TS_ASSERT_THROWS(def.end(), IllegalArgumentException);
+#ifdef CVC4_ASSERTIONS
+ TS_ASSERT_THROWS(def.getNumChildren(), AssertionException);
+ TS_ASSERT_THROWS(def.begin(), AssertionException);
+ TS_ASSERT_THROWS(def.end(), AssertionException);
+#endif /* CVC4_ASSERTIONS */
NodeBuilder<> spec(specKind);
TS_ASSERT_EQUALS(spec.getKind(), specKind);
NodeBuilder<> from_nm(d_nm);
TS_ASSERT_EQUALS(from_nm.getKind(), UNDEFINED_KIND);
- TS_ASSERT_THROWS(from_nm.getNumChildren(), IllegalArgumentException);
- TS_ASSERT_THROWS(from_nm.begin(), IllegalArgumentException);
- TS_ASSERT_THROWS(from_nm.end(), IllegalArgumentException);
+#ifdef CVC4_ASSERTIONS
+ TS_ASSERT_THROWS(from_nm.getNumChildren(), AssertionException);
+ TS_ASSERT_THROWS(from_nm.begin(), AssertionException);
+ TS_ASSERT_THROWS(from_nm.end(), AssertionException);
+#endif /* CVC4_ASSERTIONS */
NodeBuilder<> from_nm_kind(d_nm, specKind);
TS_ASSERT_EQUALS(from_nm_kind.getKind(), specKind);
NodeBuilder<K> ws;
TS_ASSERT_EQUALS(ws.getKind(), UNDEFINED_KIND);
- TS_ASSERT_THROWS(ws.getNumChildren(), IllegalArgumentException);
- TS_ASSERT_THROWS(ws.begin(), IllegalArgumentException);
- TS_ASSERT_THROWS(ws.end(), IllegalArgumentException);
+#ifdef CVC4_ASSERTIONS
+ TS_ASSERT_THROWS(ws.getNumChildren(), AssertionException);
+ TS_ASSERT_THROWS(ws.begin(), AssertionException);
+ TS_ASSERT_THROWS(ws.end(), AssertionException);
+#endif /* CVC4_ASSERTIONS */
NodeBuilder<K> ws_kind(specKind);
TS_ASSERT_EQUALS(ws_kind.getKind(), specKind);
NodeBuilder<K> ws_from_nm(d_nm);
TS_ASSERT_EQUALS(ws_from_nm.getKind(), UNDEFINED_KIND);
- TS_ASSERT_THROWS(ws_from_nm.getNumChildren(), IllegalArgumentException);
- TS_ASSERT_THROWS(ws_from_nm.begin(), IllegalArgumentException);
- TS_ASSERT_THROWS(ws_from_nm.end(), IllegalArgumentException);
+#ifdef CVC4_ASSERTIONS
+ TS_ASSERT_THROWS(ws_from_nm.getNumChildren(), AssertionException);
+ TS_ASSERT_THROWS(ws_from_nm.begin(), AssertionException);
+ TS_ASSERT_THROWS(ws_from_nm.end(), AssertionException);
+#endif /* CVC4_ASSERTIONS */
NodeBuilder<K> ws_from_nm_kind(d_nm, specKind);
TS_ASSERT_EQUALS(ws_from_nm_kind.getKind(), specKind);
NodeBuilder<> copy(def);
TS_ASSERT_EQUALS(copy.getKind(), UNDEFINED_KIND);
- TS_ASSERT_THROWS(copy.getNumChildren(), IllegalArgumentException);
- TS_ASSERT_THROWS(copy.begin(), IllegalArgumentException);
- TS_ASSERT_THROWS(copy.end(), IllegalArgumentException);
+#ifdef CVC4_ASSERTIONS
+ TS_ASSERT_THROWS(copy.getNumChildren(), AssertionException);
+ TS_ASSERT_THROWS(copy.begin(), AssertionException);
+ TS_ASSERT_THROWS(copy.end(), AssertionException);
+#endif /* CVC4_ASSERTIONS */
NodeBuilder<K> cp_ws(ws);
TS_ASSERT_EQUALS(cp_ws.getKind(), UNDEFINED_KIND);
- TS_ASSERT_THROWS(cp_ws.getNumChildren(), IllegalArgumentException);
- TS_ASSERT_THROWS(cp_ws.begin(), IllegalArgumentException);
- TS_ASSERT_THROWS(cp_ws.end(), IllegalArgumentException);
+#ifdef CVC4_ASSERTIONS
+ TS_ASSERT_THROWS(cp_ws.getNumChildren(), AssertionException);
+ TS_ASSERT_THROWS(cp_ws.begin(), AssertionException);
+ TS_ASSERT_THROWS(cp_ws.end(), AssertionException);
+#endif /* CVC4_ASSERTIONS */
NodeBuilder<K-10> cp_from_larger(ws);
TS_ASSERT_EQUALS(cp_from_larger.getKind(), UNDEFINED_KIND);
- TS_ASSERT_THROWS(cp_from_larger.getNumChildren(), IllegalArgumentException);
- TS_ASSERT_THROWS(cp_from_larger.begin(), IllegalArgumentException);
- TS_ASSERT_THROWS(cp_from_larger.end(), IllegalArgumentException);
+#ifdef CVC4_ASSERTIONS
+ TS_ASSERT_THROWS(cp_from_larger.getNumChildren(), AssertionException);
+ TS_ASSERT_THROWS(cp_from_larger.begin(), AssertionException);
+ TS_ASSERT_THROWS(cp_from_larger.end(), AssertionException);
+#endif /* CVC4_ASSERTIONS */
NodeBuilder<K+10> cp_from_smaller(ws);
TS_ASSERT_EQUALS(cp_from_smaller.getKind(), UNDEFINED_KIND);
- TS_ASSERT_THROWS(cp_from_smaller.getNumChildren(), IllegalArgumentException);
- TS_ASSERT_THROWS(cp_from_smaller.begin(), IllegalArgumentException);
- TS_ASSERT_THROWS(cp_from_smaller.end(), IllegalArgumentException);
+#ifdef CVC4_ASSERTIONS
+ TS_ASSERT_THROWS(cp_from_smaller.getNumChildren(), AssertionException);
+ TS_ASSERT_THROWS(cp_from_smaller.begin(), AssertionException);
+ TS_ASSERT_THROWS(cp_from_smaller.end(), AssertionException);
+#endif /* CVC4_ASSERTIONS */
}
void testDestructor() {
Node x( d_nm->mkVar( *d_integerType ) );
NodeBuilder<> nb;
- TS_ASSERT_THROWS(nb.getNumChildren(), IllegalArgumentException);
+#ifdef CVC4_ASSERTIONS
+ TS_ASSERT_THROWS(nb.getNumChildren(), AssertionException);
+#endif /* CVC4_ASSERTIONS */
nb << PLUS << x << x;
TS_ASSERT_EQUALS(nb.getNumChildren(), 2u);
Node n = nb;// avoid warning on clear()
nb.clear();
- TS_ASSERT_THROWS(nb.getNumChildren(), IllegalArgumentException);
+#ifdef CVC4_ASSERTIONS
+ TS_ASSERT_THROWS(nb.getNumChildren(), AssertionException);
+#endif /* CVC4_ASSERTIONS */
nb.clear(PLUS);
TS_ASSERT_EQUALS(nb.getNumChildren(), 0u);
nb << x << x << x;
NodeBuilder<> nb;
TS_ASSERT_EQUALS(nb.getKind(), UNDEFINED_KIND);
- TS_ASSERT_THROWS(nb.getNumChildren(), IllegalArgumentException);
- TS_ASSERT_THROWS(nb.begin(), IllegalArgumentException);
- TS_ASSERT_THROWS(nb.end(), IllegalArgumentException);
+#ifdef CVC4_ASSERTIONS
+ TS_ASSERT_THROWS(nb.getNumChildren(), AssertionException);
+ TS_ASSERT_THROWS(nb.begin(), AssertionException);
+ TS_ASSERT_THROWS(nb.end(), AssertionException);
+#endif /* CVC4_ASSERTIONS */
nb << specKind;
push_back(nb, K);
nb.clear();
TS_ASSERT_EQUALS(nb.getKind(), UNDEFINED_KIND);
- TS_ASSERT_THROWS(nb.getNumChildren(), IllegalArgumentException);
- TS_ASSERT_THROWS(nb.begin(), IllegalArgumentException);
- TS_ASSERT_THROWS(nb.end(), IllegalArgumentException);
+#ifdef CVC4_ASSERTIONS
+ TS_ASSERT_THROWS(nb.getNumChildren(), AssertionException);
+ TS_ASSERT_THROWS(nb.begin(), AssertionException);
+ TS_ASSERT_THROWS(nb.end(), AssertionException);
+#endif /* CVC4_ASSERTIONS */
nb << specKind;
push_back(nb, K);
nb.clear();
TS_ASSERT_EQUALS(nb.getKind(), UNDEFINED_KIND);
- TS_ASSERT_THROWS(nb.getNumChildren(), IllegalArgumentException);
- TS_ASSERT_THROWS(nb.begin(), IllegalArgumentException);
- TS_ASSERT_THROWS(nb.end(), IllegalArgumentException);
+#ifdef CVC4_ASSERTIONS
+ TS_ASSERT_THROWS(nb.getNumChildren(), AssertionException);
+ TS_ASSERT_THROWS(nb.begin(), AssertionException);
+ TS_ASSERT_THROWS(nb.end(), AssertionException);
+#endif /* CVC4_ASSERTIONS */
}
void testStreamInsertionKind() {