From b85e9ba95f215c12575417fdfc95fbdcad4de550 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sun, 20 Jul 2008 06:00:06 -0400 Subject: Everything but main.cc is compiling again (but with much #if 0'd code). --- gnucash.cc | 2 +- main.cc | 57 +++++----------- textual.cc | 8 ++- valexpr.cc | 219 ++++++++++++++++++++++++++++--------------------------------- valexpr.h | 7 +- walk.cc | 24 ++++--- 6 files changed, 140 insertions(+), 177 deletions(-) diff --git a/gnucash.cc b/gnucash.cc index 7ba0b815..abec0ed8 100644 --- a/gnucash.cc +++ b/gnucash.cc @@ -179,7 +179,7 @@ static void endElement(void *userData, const char *name) xact->state = curr_state; xact->amount = value; if (value != curr_value) - xact->cost = new amount_t(curr_value); + xact->cost = curr_value; xact->beg_pos = beg_pos; xact->beg_line = beg_line; diff --git a/main.cc b/main.cc index dec19d2c..01b8eb97 100644 --- a/main.cc +++ b/main.cc @@ -135,16 +135,20 @@ static int read_and_report(ledger::report_t& report, int argc, char * argv[], else #endif if (verb == "xml") +#if 0 command = bind(xml_command, _1); +#else + ; +#endif else if (verb == "expr") ; else if (verb == "xpath") ; else if (verb == "parse") { - xml::xpath_t expr(*arg); - xml::document_t temp(xml::LEDGER_NODE); + value_expr expr(*arg); - xml::xpath_t::context_scope_t doc_scope(report, &temp); +#if 0 + expr::context_scope_t doc_scope(report, &temp); IF_INFO() { std::cout << "Value expression tree:" << std::endl; @@ -169,6 +173,7 @@ static int read_and_report(ledger::report_t& report, int argc, char * argv[], } std::cout << expr.calc(doc_scope).strip_annotations() << std::endl; +#endif return 0; } @@ -177,7 +182,7 @@ static int read_and_report(ledger::report_t& report, int argc, char * argv[], std::strcpy(buf, "command_"); std::strcat(buf, verb.c_str()); - if (xml::xpath_t::ptr_op_t def = report.lookup(buf)) + if (expr::ptr_op_t def = report.lookup(buf)) command = def->as_function(); if (! command) @@ -187,17 +192,19 @@ static int read_and_report(ledger::report_t& report, int argc, char * argv[], // Parse the initialization file, which can only be textual; then // parse the journal data. +#if 0 session.read_init(); +#endif INFO_START(journal, "Read journal file"); - xml::document_t xml_document(xml::LEDGER_NODE); - journal_t * journal = session.create_journal(); - xml::journal_builder_t builder(xml_document, journal); + journal_t * journal = session.create_journal(); +#if 0 if (! session.read_data(builder, journal, report.account)) throw_(parse_error, "Failed to locate any journal entries; " "did you specify a valid file with -f?"); +#endif INFO_FINISH(journal); @@ -259,10 +266,10 @@ static int read_and_report(ledger::report_t& report, int argc, char * argv[], // Are we handling the expr commands? Do so now. - xml::xpath_t::context_scope_t doc_scope(report, &xml_document); + expr::context_scope_t doc_scope(report, &xml_document); if (verb == "expr") { - xml::xpath_t expr(*arg); + value_expr expr(*arg); IF_INFO() { *out << "Value expression tree:" << std::endl; @@ -278,38 +285,6 @@ static int read_and_report(ledger::report_t& report, int argc, char * argv[], return 0; } - else if (verb == "xpath") { - std::cout << "XPath parsed: "; - - xml::xpath_t xpath(*arg); - xpath.print(*out, doc_scope); - *out << std::endl; - - IF_INFO() { - *out << "Raw results:" << std::endl; - - foreach (const value_t& value, xpath.find_all(doc_scope)) { - if (value.is_xml_node()) - value.as_xml_node()->print(std::cout); - else - std::cout << value; - std::cout << std::endl; - } - - *out << "Compiled results:" << std::endl; - } - - xml::compile_node(xml_document, report); - - foreach (const value_t& value, xpath.find_all(doc_scope)) { - if (value.is_xml_node()) - value.as_xml_node()->print(std::cout); - else - std::cout << value; - std::cout << std::endl; - } - return 0; - } // Apply transforms to the hierarchical document structure diff --git a/textual.cc b/textual.cc index 9a1aa753..b83ae82c 100644 --- a/textual.cc +++ b/textual.cc @@ -209,7 +209,7 @@ transaction_t * parse_transaction(char * line, account_t * account, } if (in.good() && ! in.eof()) { - xact->cost = new amount_t; + xact->cost = amount_t(); try { unsigned long beg = (long)in.tellg(); @@ -734,7 +734,9 @@ unsigned int textual_parser_t::parse(std::istream& in, if (p) *p++ = '\0'; } +#if 0 process_option(config_options, line + 2, p); +#endif break; } @@ -835,13 +837,15 @@ unsigned int textual_parser_t::parse(std::istream& in, // parser to resolve alias references. account_t * acct = account_stack.front()->find_account(e); std::pair result - = account_aliases.insert(accounts_map::pair_type(b, acct)); + = account_aliases.insert(accounts_map::value_type(b, acct)); assert(result.second); } } else if (word == "def") { +#if 0 if (! expr::global_scope.get()) init_value_expr(); +#endif parse_value_definition(p); } break; diff --git a/valexpr.cc b/valexpr.cc index 059cbc5d..5e0a1037 100644 --- a/valexpr.cc +++ b/valexpr.cc @@ -9,7 +9,7 @@ value_expr total_expr; namespace expr { -std::auto_ptr global_scope; +std::auto_ptr global_scope; datetime_t terminus; details_t::details_t(const transaction_t& _xact) @@ -553,10 +553,10 @@ void op_t::compute(value_t& result, const details_t& details, case O_COM: if (! left()) throw new compute_error("Comma operator missing left operand", - new valexpr_context(this)); + new valexpr_context(const_cast(this))); if (! right()) throw new compute_error("Comma operator missing right operand", - new valexpr_context(this)); + new valexpr_context(const_cast(this))); left()->compute(result, details, context); right()->compute(result, details, context); break; @@ -696,7 +696,7 @@ void op_t::compute(value_t& result, const details_t& details, catch (error * err) { if (err->context.empty() || ! dynamic_cast(err->context.back())) - err->context.push_back(new valexpr_context(this)); + err->context.push_back(new valexpr_context(const_cast(this))); throw err; } } @@ -823,7 +823,7 @@ ptr_op_t parse_value_term(std::istream& in, scope_t * scope, } if (definition) { - std::auto_ptr params(new call_scope_t(scope)); + std::auto_ptr params(new call_scope_t(*scope)); long arg_index = 0; if (have_args) { @@ -846,7 +846,7 @@ ptr_op_t parse_value_term(std::istream& in, scope_t * scope, // an O_ARG value. node.reset(new op_t(op_t::O_ARG)); node->set_left(new op_t(op_t::ARG_INDEX)); - node->left->arg_index = arg_index++; + node->left()->set_long(arg_index++); params->define(ident, node.release()); } @@ -864,7 +864,7 @@ ptr_op_t parse_value_term(std::istream& in, scope_t * scope, node.reset(new op_t(op_t::O_DEF)); node->set_left(new op_t(op_t::ARG_INDEX)); - node->left->arg_index = arg_index; + node->left()->set_long(arg_index); node->set_right(def.release()); scope->define(buf, node.get()); @@ -883,7 +883,7 @@ ptr_op_t parse_value_term(std::istream& in, scope_t * scope, } else if (def->kind == op_t::O_DEF) { node.reset(new op_t(op_t::O_REF)); - node->set_left(def->right); + node->set_left(def->right()); unsigned int count = 0; if (have_args) { @@ -904,10 +904,11 @@ ptr_op_t parse_value_term(std::istream& in, scope_t * scope, } } - if (count != def->left->arg_index) { + if (count != def->left()->as_long()) { std::ostringstream errmsg; errmsg << "Wrong number of arguments to '" << buf - << "': saw " << count << ", wanted " << def->left->arg_index; + << "': saw " << count + << ", wanted " << def->left()->as_long(); throw new value_expr_error(errmsg.str()); } } @@ -928,6 +929,7 @@ ptr_op_t parse_value_term(std::istream& in, scope_t * scope, break; // Other +#if 0 case 'c': case 'C': case 'p': @@ -983,6 +985,7 @@ ptr_op_t parse_value_term(std::istream& in, scope_t * scope, node->mask = new mask_t(buf); break; } +#endif case '{': { amount_t temp; @@ -991,13 +994,13 @@ ptr_op_t parse_value_term(std::istream& in, scope_t * scope, if (c != '}') unexpected(c, '}'); - node.reset(new op_t(op_t::CONSTANT)); - node->value = new value_t(temp); + node.reset(new op_t(op_t::VALUE)); + node->set_value(temp); break; } case '(': { - std::auto_ptr locals(new scope_t(scope)); + std::auto_ptr locals(new symbol_scope_t(*scope)); node.reset(parse_value_expr(in, locals.get(), flags | PARSE_VALEXPR_PARTIAL)); in.get(c); @@ -1013,8 +1016,8 @@ ptr_op_t parse_value_term(std::istream& in, scope_t * scope, in.get(c); interval_t timespan(buf); - node.reset(new op_t(op_t::CONSTANT)); - node->value = new value_t(timespan.first()); + node.reset(new op_t(op_t::VALUE)); + node->set_value(timespan.first()); break; } @@ -1079,8 +1082,8 @@ ptr_op_t parse_add_expr(std::istream& in, scope_t * scope, char c; in.get(c); value_expr expr(parse_mul_expr(in, scope, flags)); - if (expr->kind == op_t::CONSTANT) { - expr->value->negate(); + if (expr->kind == op_t::VALUE) { + expr->as_value().in_place_negate(); return expr.release(); } node.reset(new op_t(op_t::O_NEG)); @@ -1219,12 +1222,12 @@ ptr_op_t parse_boolean_expr(std::istream& in, scope_t * scope, node.reset(new op_t(op_t::O_QUES)); node->set_left(prev.release()); node->set_right(new op_t(op_t::O_COL)); - node->right->set_left(parse_logic_expr(in, scope, flags)); + node->right()->set_left(parse_logic_expr(in, scope, flags)); c = peek_next_nonws(in); if (c != ':') unexpected(c, ':'); in.get(c); - node->right->set_right(parse_logic_expr(in, scope, flags)); + node->right()->set_right(parse_logic_expr(in, scope, flags)); break; } @@ -1242,8 +1245,8 @@ ptr_op_t parse_boolean_expr(std::istream& in, scope_t * scope, void init_value_expr() { - global_scope.reset(new scope_t()); - scope_t * globals = global_scope.get(); + global_scope.reset(new symbol_scope_t()); + symbol_scope_t * globals = global_scope.get(); ptr_op_t node; @@ -1318,26 +1321,26 @@ void init_value_expr() globals->define("total_cost", node); // Relating to format_t - globals->define("t", new op_t(op_t::VALUE_EXPR)); - globals->define("T", new op_t(op_t::TOTAL_EXPR)); + globals->define("t", ptr_op_t(new op_t(op_t::VALUE_EXPR))); + globals->define("T", ptr_op_t(new op_t(op_t::TOTAL_EXPR))); // Functions node = new op_t(op_t::O_DEF); node->set_left(new op_t(op_t::ARG_INDEX)); - node->left->arg_index = 1; + node->left()->set_long(1); node->set_right(new op_t(op_t::F_ABS)); globals->define("U", node); globals->define("abs", node); node = new op_t(op_t::O_DEF); node->set_left(new op_t(op_t::ARG_INDEX)); - node->left->arg_index = 1; + node->left()->set_long(1); node->set_right(new op_t(op_t::F_ROUND)); globals->define("round", node); node = new op_t(op_t::O_DEF); node->set_left(new op_t(op_t::ARG_INDEX)); - node->left->arg_index = 1; + node->left()->set_long(1); node->set_right(new op_t(op_t::F_QUANTITY)); globals->define("S", node); globals->define("quant", node); @@ -1345,21 +1348,21 @@ void init_value_expr() node = new op_t(op_t::O_DEF); node->set_left(new op_t(op_t::ARG_INDEX)); - node->left->arg_index = 1; + node->left()->set_long(1); node->set_right(new op_t(op_t::F_COMMODITY)); globals->define("comm", node); globals->define("commodity", node); node = new op_t(op_t::O_DEF); node->set_left(new op_t(op_t::ARG_INDEX)); - node->left->arg_index = 2; + node->left()->set_long(2); node->set_right(new op_t(op_t::F_SET_COMMODITY)); globals->define("setcomm", node); globals->define("set_commodity", node); node = new op_t(op_t::O_DEF); node->set_left(new op_t(op_t::ARG_INDEX)); - node->left->arg_index = 1; + node->left()->set_long(1); node->set_right(new op_t(op_t::F_ARITH_MEAN)); globals->define("A", node); globals->define("avg", node); @@ -1368,7 +1371,7 @@ void init_value_expr() node = new op_t(op_t::O_DEF); node->set_left(new op_t(op_t::ARG_INDEX)); - node->left->arg_index = 2; + node->left()->set_long(2); node->set_right(new op_t(op_t::F_VALUE)); globals->define("P", node); @@ -1379,37 +1382,37 @@ void init_value_expr() node = new op_t(op_t::O_DEF); node->set_left(new op_t(op_t::ARG_INDEX)); - node->left->arg_index = 1; + node->left()->set_long(1); node->set_right(new op_t(op_t::F_PRICE)); globals->define("priceof", node); node = new op_t(op_t::O_DEF); node->set_left(new op_t(op_t::ARG_INDEX)); - node->left->arg_index = 1; + node->left()->set_long(1); node->set_right(new op_t(op_t::F_DATE)); globals->define("dateof", node); node = new op_t(op_t::O_DEF); node->set_left(new op_t(op_t::ARG_INDEX)); - node->left->arg_index = 2; + node->left()->set_long(2); node->set_right(new op_t(op_t::F_DATECMP)); globals->define("datecmp", node); node = new op_t(op_t::O_DEF); node->set_left(new op_t(op_t::ARG_INDEX)); - node->left->arg_index = 1; + node->left()->set_long(1); node->set_right(new op_t(op_t::F_YEAR)); globals->define("yearof", node); node = new op_t(op_t::O_DEF); node->set_left(new op_t(op_t::ARG_INDEX)); - node->left->arg_index = 1; + node->left()->set_long(1); node->set_right(new op_t(op_t::F_MONTH)); globals->define("monthof", node); node = new op_t(op_t::O_DEF); node->set_left(new op_t(op_t::ARG_INDEX)); - node->left->arg_index = 1; + node->left()->set_long(1); node->set_right(new op_t(op_t::F_DAY)); globals->define("dayof", node); @@ -1444,8 +1447,8 @@ ptr_op_t parse_value_expr(std::istream& in, scope_t * scope, if (! global_scope.get()) init_value_expr(); - std::auto_ptr this_scope(new scope_t(scope ? scope : - global_scope.get())); + std::auto_ptr + this_scope(new symbol_scope_t(scope ? *scope : *global_scope.get())); value_expr node; node.reset(parse_boolean_expr(in, this_scope.get(), flags)); @@ -1489,19 +1492,6 @@ ptr_op_t parse_value_expr(std::istream& in, scope_t * scope, return node.release(); } -valexpr_context::valexpr_context(const ledger::ptr_op_t _expr, - const string& desc) throw() - : error_context(desc), expr(_expr), error_node(_expr) -{ - error_node->acquire(); -} - -valexpr_context::~valexpr_context() throw() -{ - if (expr) expr->release(); - if (error_node) error_node->release(); -} - void valexpr_context::describe(std::ostream& out) const throw() { if (! expr) { @@ -1516,8 +1506,7 @@ void valexpr_context::describe(std::ostream& out) const throw() unsigned long start = (long)out.tellp() - 1; unsigned long begin; unsigned long end; - bool found = ledger::print_value_expr(out, expr, true, - error_node, &begin, &end); + bool found = print_value_expr(out, expr, true, error_node, &begin, &end); out << std::endl; if (found) { out << " "; @@ -1531,12 +1520,12 @@ void valexpr_context::describe(std::ostream& out) const throw() } } -bool print_value_expr(std::ostream& out, - const ptr_op_t node, - const bool relaxed, - const ptr_op_t op_to_find, - unsigned long * start_pos, - unsigned long * end_pos) +bool print_value_expr(std::ostream& out, + const ptr_op_t node, + const bool relaxed, + const ptr_op_t op_to_find, + unsigned long * start_pos, + unsigned long * end_pos) { bool found = false; @@ -1549,22 +1538,22 @@ bool print_value_expr(std::ostream& out, switch (node->kind) { case op_t::ARG_INDEX: - out << node->arg_index; + out << node->as_long(); break; - case op_t::CONSTANT: - switch (node->value->type()) { + case op_t::VALUE: + switch (node->as_value().type()) { case value_t::BOOLEAN: assert(false); break; case value_t::DATETIME: - out << '[' << *(node->value) << ']'; + out << '[' << node->as_value().as_datetime() << ']'; break; case value_t::INTEGER: case value_t::AMOUNT: if (! relaxed) out << '{'; - out << *(node->value); + out << node->as_value(); if (! relaxed) out << '}'; break; @@ -1647,6 +1636,7 @@ bool print_value_expr(std::ostream& out, case op_t::F_DAY: symbol = "dayof"; break; +#if 0 case op_t::F_CODE_MASK: out << "c/" << node->mask->expr.str() << "/"; break; @@ -1665,180 +1655,181 @@ bool print_value_expr(std::ostream& out, case op_t::F_COMMODITY_MASK: out << "C/" << node->mask->expr.str() << "/"; break; +#endif case op_t::O_NOT: out << "!"; - if (print_value_expr(out, node->left, relaxed, op_to_find, start_pos, end_pos)) + if (print_value_expr(out, node->left(), relaxed, op_to_find, start_pos, end_pos)) found = true; break; case op_t::O_NEG: out << "-"; - if (print_value_expr(out, node->left, relaxed, op_to_find, start_pos, end_pos)) + if (print_value_expr(out, node->left(), relaxed, op_to_find, start_pos, end_pos)) found = true; break; case op_t::O_PERC: out << "%"; - if (print_value_expr(out, node->left, relaxed, op_to_find, start_pos, end_pos)) + if (print_value_expr(out, node->left(), relaxed, op_to_find, start_pos, end_pos)) found = true; break; case op_t::O_ARG: - out << "@arg" << node->arg_index; + out << "@arg" << node->as_long(); break; case op_t::O_DEF: out << "left, relaxed, op_to_find, start_pos, end_pos)) + if (print_value_expr(out, node->left(), relaxed, op_to_find, start_pos, end_pos)) found = true; out << "\" value=\""; - if (print_value_expr(out, node->right, relaxed, op_to_find, start_pos, end_pos)) + if (print_value_expr(out, node->right(), relaxed, op_to_find, start_pos, end_pos)) found = true; out << "\">"; break; case op_t::O_REF: - if (print_value_expr(out, node->left, relaxed, op_to_find, start_pos, end_pos)) + if (print_value_expr(out, node->left(), relaxed, op_to_find, start_pos, end_pos)) found = true; - if (node->right) { + if (node->right()) { out << "("; - if (print_value_expr(out, node->right, relaxed, op_to_find, start_pos, end_pos)) + if (print_value_expr(out, node->right(), relaxed, op_to_find, start_pos, end_pos)) found = true; out << ")"; } break; case op_t::O_COM: - if (node->left && - print_value_expr(out, node->left, relaxed, op_to_find, start_pos, end_pos)) + if (node->left() && + print_value_expr(out, node->left(), relaxed, op_to_find, start_pos, end_pos)) found = true; out << ", "; - if (node->right && - print_value_expr(out, node->right, relaxed, op_to_find, start_pos, end_pos)) + if (node->right() && + print_value_expr(out, node->right(), relaxed, op_to_find, start_pos, end_pos)) found = true; break; case op_t::O_QUES: out << "("; - if (print_value_expr(out, node->left, relaxed, op_to_find, start_pos, end_pos)) + if (print_value_expr(out, node->left(), relaxed, op_to_find, start_pos, end_pos)) found = true; out << " ? "; - if (print_value_expr(out, node->right, relaxed, op_to_find, start_pos, end_pos)) + if (print_value_expr(out, node->right(), relaxed, op_to_find, start_pos, end_pos)) found = true; out << ")"; break; case op_t::O_COL: - if (print_value_expr(out, node->left, relaxed, op_to_find, start_pos, end_pos)) + if (print_value_expr(out, node->left(), relaxed, op_to_find, start_pos, end_pos)) found = true; out << " : "; - if (print_value_expr(out, node->right, relaxed, op_to_find, start_pos, end_pos)) + if (print_value_expr(out, node->right(), relaxed, op_to_find, start_pos, end_pos)) found = true; break; case op_t::O_AND: out << "("; - if (print_value_expr(out, node->left, relaxed, op_to_find, start_pos, end_pos)) + if (print_value_expr(out, node->left(), relaxed, op_to_find, start_pos, end_pos)) found = true; out << " & "; - if (print_value_expr(out, node->right, relaxed, op_to_find, start_pos, end_pos)) + if (print_value_expr(out, node->right(), relaxed, op_to_find, start_pos, end_pos)) found = true; out << ")"; break; case op_t::O_OR: out << "("; - if (print_value_expr(out, node->left, relaxed, op_to_find, start_pos, end_pos)) + if (print_value_expr(out, node->left(), relaxed, op_to_find, start_pos, end_pos)) found = true; out << " | "; - if (print_value_expr(out, node->right, relaxed, op_to_find, start_pos, end_pos)) + if (print_value_expr(out, node->right(), relaxed, op_to_find, start_pos, end_pos)) found = true; out << ")"; break; case op_t::O_NEQ: out << "("; - if (print_value_expr(out, node->left, relaxed, op_to_find, start_pos, end_pos)) + if (print_value_expr(out, node->left(), relaxed, op_to_find, start_pos, end_pos)) found = true; out << " != "; - if (print_value_expr(out, node->right, relaxed, op_to_find, start_pos, end_pos)) + if (print_value_expr(out, node->right(), relaxed, op_to_find, start_pos, end_pos)) found = true; out << ")"; break; case op_t::O_EQ: out << "("; - if (print_value_expr(out, node->left, relaxed, op_to_find, start_pos, end_pos)) + if (print_value_expr(out, node->left(), relaxed, op_to_find, start_pos, end_pos)) found = true; out << " == "; - if (print_value_expr(out, node->right, relaxed, op_to_find, start_pos, end_pos)) + if (print_value_expr(out, node->right(), relaxed, op_to_find, start_pos, end_pos)) found = true; out << ")"; break; case op_t::O_LT: out << "("; - if (print_value_expr(out, node->left, relaxed, op_to_find, start_pos, end_pos)) + if (print_value_expr(out, node->left(), relaxed, op_to_find, start_pos, end_pos)) found = true; out << " < "; - if (print_value_expr(out, node->right, relaxed, op_to_find, start_pos, end_pos)) + if (print_value_expr(out, node->right(), relaxed, op_to_find, start_pos, end_pos)) found = true; out << ")"; break; case op_t::O_LTE: out << "("; - if (print_value_expr(out, node->left, relaxed, op_to_find, start_pos, end_pos)) + if (print_value_expr(out, node->left(), relaxed, op_to_find, start_pos, end_pos)) found = true; out << " <= "; - if (print_value_expr(out, node->right, relaxed, op_to_find, start_pos, end_pos)) + if (print_value_expr(out, node->right(), relaxed, op_to_find, start_pos, end_pos)) found = true; out << ")"; break; case op_t::O_GT: out << "("; - if (print_value_expr(out, node->left, relaxed, op_to_find, start_pos, end_pos)) + if (print_value_expr(out, node->left(), relaxed, op_to_find, start_pos, end_pos)) found = true; out << " > "; - if (print_value_expr(out, node->right, relaxed, op_to_find, start_pos, end_pos)) + if (print_value_expr(out, node->right(), relaxed, op_to_find, start_pos, end_pos)) found = true; out << ")"; break; case op_t::O_GTE: out << "("; - if (print_value_expr(out, node->left, relaxed, op_to_find, start_pos, end_pos)) + if (print_value_expr(out, node->left(), relaxed, op_to_find, start_pos, end_pos)) found = true; out << " >= "; - if (print_value_expr(out, node->right, relaxed, op_to_find, start_pos, end_pos)) + if (print_value_expr(out, node->right(), relaxed, op_to_find, start_pos, end_pos)) found = true; out << ")"; break; case op_t::O_ADD: out << "("; - if (print_value_expr(out, node->left, relaxed, op_to_find, start_pos, end_pos)) + if (print_value_expr(out, node->left(), relaxed, op_to_find, start_pos, end_pos)) found = true; out << " + "; - if (print_value_expr(out, node->right, relaxed, op_to_find, start_pos, end_pos)) + if (print_value_expr(out, node->right(), relaxed, op_to_find, start_pos, end_pos)) found = true; out << ")"; break; case op_t::O_SUB: out << "("; - if (print_value_expr(out, node->left, relaxed, op_to_find, start_pos, end_pos)) + if (print_value_expr(out, node->left(), relaxed, op_to_find, start_pos, end_pos)) found = true; out << " - "; - if (print_value_expr(out, node->right, relaxed, op_to_find, start_pos, end_pos)) + if (print_value_expr(out, node->right(), relaxed, op_to_find, start_pos, end_pos)) found = true; out << ")"; break; case op_t::O_MUL: out << "("; - if (print_value_expr(out, node->left, relaxed, op_to_find, start_pos, end_pos)) + if (print_value_expr(out, node->left(), relaxed, op_to_find, start_pos, end_pos)) found = true; out << " * "; - if (print_value_expr(out, node->right, relaxed, op_to_find, start_pos, end_pos)) + if (print_value_expr(out, node->right(), relaxed, op_to_find, start_pos, end_pos)) found = true; out << ")"; break; case op_t::O_DIV: out << "("; - if (print_value_expr(out, node->left, relaxed, op_to_find, start_pos, end_pos)) + if (print_value_expr(out, node->left(), relaxed, op_to_find, start_pos, end_pos)) found = true; out << " / "; - if (print_value_expr(out, node->right, relaxed, op_to_find, start_pos, end_pos)) + if (print_value_expr(out, node->right(), relaxed, op_to_find, start_pos, end_pos)) found = true; out << ")"; break; @@ -1873,10 +1864,10 @@ void dump_value_expr(std::ostream& out, const ptr_op_t node, switch (node->kind) { case op_t::ARG_INDEX: - out << "ARG_INDEX - " << node->arg_index; + out << "ARG_INDEX - " << node->as_long(); break; - case op_t::CONSTANT: - out << "CONSTANT - " << *(node->value); + case op_t::VALUE: + out << "VALUE - " << node->as_value(); break; case op_t::AMOUNT: out << "AMOUNT"; break; @@ -1953,15 +1944,9 @@ void dump_value_expr(std::ostream& out, const ptr_op_t node, out << " (" << node->refc << ')' << std::endl; if (node->kind > op_t::TERMINALS) { - if (node->left) { - dump_value_expr(out, node->left, depth + 1); - if (node->right) - dump_value_expr(out, node->right, depth + 1); - } else { - assert(! node->right); - } - } else { - assert(! node->left); + dump_value_expr(out, node->left(), depth + 1); + if (node->right()) + dump_value_expr(out, node->right(), depth + 1); } } diff --git a/valexpr.h b/valexpr.h index 2f349dc8..62302a87 100644 --- a/valexpr.h +++ b/valexpr.h @@ -603,8 +603,9 @@ class valexpr_context : public error_context { ptr_op_t error_node; valexpr_context(const ptr_op_t& _expr, - const string& desc = "") throw(); - virtual ~valexpr_context() throw(); + const string& desc = "") throw() + : error_context(desc), expr(_expr), error_node(_expr) {} + virtual ~valexpr_context() throw() {} virtual void describe(std::ostream& out) const throw(); }; @@ -624,7 +625,7 @@ class value_expr_error : public error { virtual ~value_expr_error() throw() {} }; -extern std::auto_ptr global_scope; +extern std::auto_ptr global_scope; extern datetime_t terminus; extern bool initialized; diff --git a/walk.cc b/walk.cc index 832d7518..58b6d03b 100644 --- a/walk.cc +++ b/walk.cc @@ -558,7 +558,7 @@ void set_comm_as_payee::operator()(transaction_t& xact) transaction_t& temp = xact_temps.back(); temp.entry = &entry; temp.state = xact.state; - temp.flags |= TRANSACTION_BULK_ALLOC; + temp.add_flags(TRANSACTION_BULK_ALLOC); entry.add_transaction(&temp); @@ -571,8 +571,8 @@ void set_code_as_payee::operator()(transaction_t& xact) entry_t& entry = entry_temps.back(); entry._date = xact.date(); - if (! xact.entry->code.empty()) - entry.payee = xact.entry->code; + if (xact.entry->code) + entry.payee = *xact.entry->code; else entry.payee = ""; @@ -580,7 +580,7 @@ void set_code_as_payee::operator()(transaction_t& xact) transaction_t& temp = xact_temps.back(); temp.entry = &entry; temp.state = xact.state; - temp.flags |= TRANSACTION_BULK_ALLOC; + temp.add_flags(TRANSACTION_BULK_ALLOC); entry.add_transaction(&temp); @@ -659,8 +659,8 @@ void budget_transactions::report_budget_items(const datetime_t& moment) xact_temps.push_back(xact); transaction_t& temp = xact_temps.back(); - temp.entry = &entry; - temp.flags |= TRANSACTION_AUTO | TRANSACTION_BULK_ALLOC; + temp.entry = &entry; + temp.add_flags(TRANSACTION_AUTO | TRANSACTION_BULK_ALLOC); temp.amount.negate(); entry.add_transaction(&temp); @@ -750,8 +750,7 @@ void forecast_transactions::flush() xact_temps.push_back(xact); transaction_t& temp = xact_temps.back(); temp.entry = &entry; - temp.flags |= TRANSACTION_AUTO; - temp.flags |= TRANSACTION_BULK_ALLOC; + temp.add_flags(TRANSACTION_AUTO | TRANSACTION_BULK_ALLOC); entry.add_transaction(&temp); datetime_t next = (*least).first.increment(begin); @@ -873,7 +872,7 @@ void walk_accounts(account_t& account, for (accounts_map::const_iterator i = account.accounts.begin(); i != account.accounts.end(); i++) - walk_accounts(*(*i).second, handler, NULL); + walk_accounts(*(*i).second, handler); } } @@ -882,9 +881,8 @@ void walk_accounts(account_t& account, const string& sort_string) { if (! sort_string.empty()) { - value_expr sort_order; - sort_order.reset(parse_value_expr(sort_string)); - walk_accounts(account, handler, sort_order); + value_expr sorter(sort_string); + walk_accounts(account, handler, optional(sorter)); } else { walk_accounts(account, handler); } @@ -917,7 +915,7 @@ void walk_commodities(commodity_pool_t::commodities_by_ident& commodities, transaction_t& temp = xact_temps.back(); temp.entry = &entry_temps.back(); temp.amount = (*j).second; - temp.flags |= TRANSACTION_BULK_ALLOC; + temp.add_flags(TRANSACTION_BULK_ALLOC); entry_temps.back().add_transaction(&temp); handler(xact_temps.back()); -- cgit v1.2.3