Removed more dead code and todo comments, and made it possible to stream
compiled value expressions.
This commit is contained in:
parent
1c079630cf
commit
08488d4cd7
5 changed files with 21 additions and 20 deletions
|
|
@ -32,7 +32,6 @@
|
|||
#include "expr.h"
|
||||
#include "parser.h"
|
||||
#include "op.h"
|
||||
#include "scope.h" // jww (2008-08-01): not necessary
|
||||
|
||||
namespace ledger {
|
||||
|
||||
|
|
@ -160,10 +159,10 @@ value_t expr_t::eval(const string& _expr, scope_t& scope)
|
|||
return expr_t(_expr).calc(scope);
|
||||
}
|
||||
|
||||
void expr_t::print(std::ostream& out, scope_t& scope) const
|
||||
void expr_t::print(std::ostream& out) const
|
||||
{
|
||||
if (ptr) {
|
||||
op_t::print_context_t context(scope);
|
||||
op_t::print_context_t context;
|
||||
ptr->print(out, context);
|
||||
}
|
||||
}
|
||||
|
|
@ -194,9 +193,7 @@ void expr_t::shutdown()
|
|||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& out, const expr_t& expr) {
|
||||
// jww (2008-08-01): shouldn't be necessary
|
||||
symbol_scope_t scope;
|
||||
expr.print(out, scope);
|
||||
expr.print(out);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@ public:
|
|||
|
||||
function_t& get_function();
|
||||
|
||||
void print(std::ostream& out, scope_t& scope) const;
|
||||
void print(std::ostream& out) const;
|
||||
void dump(std::ostream& out) const;
|
||||
void read(const char *& data);
|
||||
void write(std::ostream& out) const;
|
||||
|
|
|
|||
|
|
@ -293,7 +293,7 @@ namespace ledger {
|
|||
out << "Value expression as input: " << *arg << std::endl;
|
||||
|
||||
out << "Value expression as parsed: ";
|
||||
expr.print(out, report);
|
||||
expr.print(out);
|
||||
out << std::endl;
|
||||
|
||||
out << std::endl;
|
||||
|
|
@ -312,7 +312,7 @@ namespace ledger {
|
|||
|
||||
out << "Value expression as input: " << *arg << std::endl;
|
||||
out << "Value expression as parsed: ";
|
||||
expr.print(out, report);
|
||||
expr.print(out);
|
||||
out << std::endl;
|
||||
|
||||
out << std::endl;
|
||||
|
|
|
|||
15
src/op.cc
15
src/op.cc
|
|
@ -42,7 +42,7 @@ expr_t::ptr_op_t expr_t::op_t::compile(scope_t& scope)
|
|||
if (ptr_op_t def = scope.lookup(as_ident())) {
|
||||
// Definitions are compiled at the point of definition, not the
|
||||
// point of use.
|
||||
return def;
|
||||
return copy(def);
|
||||
}
|
||||
return this;
|
||||
|
||||
|
|
@ -74,7 +74,9 @@ value_t expr_t::op_t::calc(scope_t& scope)
|
|||
return as_value();
|
||||
|
||||
case IDENT:
|
||||
throw_(calc_error, "Unknown identifier '" << as_ident() << "'");
|
||||
if (! left())
|
||||
throw_(calc_error, "Unknown identifier '" << as_ident() << "'");
|
||||
return left()->calc(scope);
|
||||
|
||||
case FUNCTION: {
|
||||
// Evaluating a FUNCTION is the same as calling it directly; this happens
|
||||
|
|
@ -93,6 +95,9 @@ value_t expr_t::op_t::calc(scope_t& scope)
|
|||
ptr_op_t func = left();
|
||||
string name;
|
||||
|
||||
assert(func->kind == IDENT);
|
||||
func = func->left();
|
||||
|
||||
if (func->kind != FUNCTION)
|
||||
throw_(calc_error, "Calling non-function");
|
||||
|
||||
|
|
@ -433,7 +438,9 @@ void expr_t::op_t::dump(std::ostream& out, const int depth) const
|
|||
|
||||
out << " (" << refc << ')' << std::endl;
|
||||
|
||||
if (kind > TERMINALS) {
|
||||
// An identifier is a special non-terminal, in that its left() can
|
||||
// hold the compiled definition of the identifier.
|
||||
if (kind > TERMINALS || kind == IDENT) {
|
||||
if (left()) {
|
||||
left()->dump(out, depth + 1);
|
||||
if (right())
|
||||
|
|
@ -517,7 +524,7 @@ void expr_t::op_t::write(std::ostream& out) const
|
|||
binary::write_long(out, as_index());
|
||||
break;
|
||||
|
||||
case FUNCTION: // jww (2008-08-15): uh oh...
|
||||
case FUNCTION:
|
||||
default:
|
||||
assert(false);
|
||||
break;
|
||||
|
|
|
|||
11
src/op.h
11
src/op.h
|
|
@ -278,19 +278,16 @@ public:
|
|||
|
||||
struct print_context_t
|
||||
{
|
||||
scope_t& scope;
|
||||
const bool relaxed;
|
||||
const ptr_op_t& op_to_find;
|
||||
const bool relaxed;
|
||||
const ptr_op_t& op_to_find;
|
||||
ostream_pos_type * start_pos;
|
||||
ostream_pos_type * end_pos;
|
||||
|
||||
// jww (2008-08-01): Is a scope needed here?
|
||||
print_context_t(scope_t& _scope,
|
||||
const bool _relaxed = false,
|
||||
print_context_t(const bool _relaxed = false,
|
||||
const ptr_op_t& _op_to_find = ptr_op_t(),
|
||||
ostream_pos_type * _start_pos = NULL,
|
||||
ostream_pos_type * _end_pos = NULL)
|
||||
: scope(_scope), relaxed(_relaxed), op_to_find(_op_to_find),
|
||||
: relaxed(_relaxed), op_to_find(_op_to_find),
|
||||
start_pos(_start_pos), end_pos(_end_pos) {}
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue