From 5ba81765eabcb0fe0b7a865b7a2c9c6affab4a59 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Fri, 23 Jan 2009 01:09:23 -0400 Subject: Added some debug code. --- src/op.cc | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/op.cc b/src/op.cc index e8c2a8e6..2d71f8b5 100644 --- a/src/op.cc +++ b/src/op.cc @@ -37,32 +37,34 @@ namespace ledger { expr_t::ptr_op_t expr_t::op_t::compile(scope_t& scope) { - switch (kind) { - case IDENT: + if (kind == IDENT) { + DEBUG("expr.compile", "Looking up identifier '" << as_ident() << "'"); + if (ptr_op_t def = scope.lookup(as_ident())) { // Identifier references are first looked up at the point of // definition, and then at the point of every use if they could // not be found there. + if (SHOW_DEBUG("expr.compile")) { + DEBUG("expr.compile", "Found definition:"); + def->dump(*_log_stream, 0); + } return copy(def); } return this; - - default: - break; } if (kind < TERMINALS) return this; ptr_op_t lhs(left()->compile(scope)); - ptr_op_t rhs(kind > UNARY_OPERATORS && has_right() ? - right()->compile(scope) : ptr_op_t()); + ptr_op_t rhs(has_right() ? right()->compile(scope) : ptr_op_t()); if (lhs == left() && (! rhs || rhs == right())) return this; ptr_op_t intermediate(copy(lhs, rhs)); + // Reduce constants immediately if possible if (lhs->is_value() && (! rhs || rhs->is_value())) return wrap_value(intermediate->calc(scope)); -- cgit v1.2.3