summaryrefslogtreecommitdiff
path: root/src/expr/node_builder.h
diff options
context:
space:
mode:
authorMorgan Deters <mdeters@gmail.com>2010-06-03 13:22:57 +0000
committerMorgan Deters <mdeters@gmail.com>2010-06-03 13:22:57 +0000
commit25a999fdfd2e38098d0c8dc6b788c9debe4401d5 (patch)
treeebc41c53aee0c88619d82210f0a0987377d3dfb6 /src/expr/node_builder.h
parentd0dc48f0dcba16849fcc9c8649728d813f7c2305 (diff)
* Added NodeBuilder<>::getChild() to make interface more consistent
with that of Node. * If NodeBuilder<> hasn't yet been assigned a Kind, several member functions related to children now throw an IllegalArgumentException: * getNumChildren() * begin() * end() * operator[] * getChild() This is because if you later assign the NodeBuilder<> a PARAMETERIZED kind, the children are "reinterpreted" -- the first being an operator. Interface-wise, it doesn't make sense to return one thing for nb[0], then later, after setting the kind, to return another thing for nb[0]. * Fixed unit tests depending on this behavior. * Added a warning to the testing summary if unit tests didn't run (because this is likely due to compilation problems, and without a warning it looks kind of like a test success) * VERBOSE wasn't exported to the environment for unit test "make check." Fixed.
Diffstat (limited to 'src/expr/node_builder.h')
-rw-r--r--src/expr/node_builder.h24
1 files changed, 22 insertions, 2 deletions
diff --git a/src/expr/node_builder.h b/src/expr/node_builder.h
index fcc6bb364..877c50d82 100644
--- a/src/expr/node_builder.h
+++ b/src/expr/node_builder.h
@@ -418,6 +418,9 @@ public:
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");
return d_nv->begin< NodeTemplate<true> >();
}
@@ -425,6 +428,9 @@ public:
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");
return d_nv->end< NodeTemplate<true> >();
}
@@ -439,6 +445,9 @@ public:
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");
return d_nv->getMetaKind();
}
@@ -446,18 +455,29 @@ public:
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");
return d_nv->getNumChildren();
}
/** Access to children of this Node-under-construction. */
- inline Node operator[](int i) const {
+ 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(i >= 0 && unsigned(i) < d_nv->getNumChildren(),
- "index out of range for NodeBuilder[]");
+ "index out of range for NodeBuilder::getChild()");
return Node(d_nv->getChild(i));
}
+ /** Access to children of this Node-under-construction. */
+ inline Node operator[](int i) const {
+ return getChild(i);
+ }
+
/**
* "Reset" this node builder (optionally setting a new kind for it),
* using the same "inline" memory as at construction time. This
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback