summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/op.cc39
-rw-r--r--src/op.h4
2 files changed, 27 insertions, 16 deletions
diff --git a/src/op.cc b/src/op.cc
index 9b50c9f7..beffab9e 100644
--- a/src/op.cc
+++ b/src/op.cc
@@ -312,6 +312,27 @@ value_t expr_t::op_t::calc(scope_t& scope, ptr_op_t * locus)
}
}
+namespace {
+ bool print_cons(std::ostream& out, const expr_t::const_ptr_op_t op,
+ const expr_t::op_t::context_t& context)
+ {
+ bool found = false;
+
+ assert(op->left());
+ if (op->left()->print(out, context))
+ found = true;
+
+ if (op->has_right()) {
+ out << ", ";
+ if (op->right()->kind == expr_t::op_t::O_CONS)
+ found = print_cons(out, op->right(), context);
+ else if (op->right()->print(out, context))
+ found = true;
+ }
+ return found;
+ }
+}
+
bool expr_t::op_t::print(std::ostream& out, const context_t& context) const
{
bool found = false;
@@ -469,20 +490,10 @@ bool expr_t::op_t::print(std::ostream& out, const context_t& context) const
break;
case O_CONS:
- if (has_right()) {
- out << "(";
- if (left() && left()->print(out, context))
- found = true;
- for (ptr_op_t next = right(); next; next = next->right()) {
- out << ", ";
- if (next->print(out, context))
- found = true;
- }
- out << ")";
- }
- else if (left() && left()->print(out, context)) {
- found = true;
- }
+ assert(has_right());
+ out << "(";
+ found = print_cons(out, this, context);
+ out << ")";
break;
case O_DEFINE:
diff --git a/src/op.h b/src/op.h
index 94df154e..ea787d8c 100644
--- a/src/op.h
+++ b/src/op.h
@@ -243,10 +243,10 @@ private:
checked_delete(this);
}
- friend inline void intrusive_ptr_add_ref(op_t * op) {
+ friend inline void intrusive_ptr_add_ref(const op_t * op) {
op->acquire();
}
- friend inline void intrusive_ptr_release(op_t * op) {
+ friend inline void intrusive_ptr_release(const op_t * op) {
op->release();
}