diff options
author | John Wiegley <johnw@newartisans.com> | 2009-02-04 19:55:27 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2009-02-04 19:55:27 -0400 |
commit | 2d941730b1c60342be5b108d2d654723b3b7c2cb (patch) | |
tree | 6a3f4b7305857e85d2684670492007bafc3668d0 /src/expr.cc | |
parent | 73cf3b01fbd50c3a8a4fd96ff69643c28394d8fe (diff) | |
download | fork-ledger-2d941730b1c60342be5b108d2d654723b3b7c2cb.tar.gz fork-ledger-2d941730b1c60342be5b108d2d654723b3b7c2cb.tar.bz2 fork-ledger-2d941730b1c60342be5b108d2d654723b3b7c2cb.zip |
Largely removed all of Ledger's use of global variables, for the REPL's sake.
Diffstat (limited to 'src/expr.cc')
-rw-r--r-- | src/expr.cc | 43 |
1 files changed, 18 insertions, 25 deletions
diff --git a/src/expr.cc b/src/expr.cc index da45bb82..a655edf0 100644 --- a/src/expr.cc +++ b/src/expr.cc @@ -35,8 +35,6 @@ namespace ledger { -std::auto_ptr<expr_t::parser_t> expr_t::parser; - expr_t::expr_t() : compiled(false) { TRACE_CTOR(expr_t, ""); @@ -52,17 +50,15 @@ expr_t::expr_t(const string& _str, const uint_least8_t flags) : str(_str), compiled(false) { TRACE_CTOR(expr_t, "const string&"); - if (! _str.empty()) - ptr = parser->parse(str, flags); + parse(str, flags); } expr_t::expr_t(std::istream& in, const uint_least8_t flags) : compiled(false) { TRACE_CTOR(expr_t, "std::istream&"); - - ptr = parser->parse(in, flags); + parse(in, flags); } expr_t::expr_t(const ptr_op_t& _ptr, const string& _str) @@ -88,22 +84,18 @@ expr_t& expr_t::operator=(const expr_t& _expr) void expr_t::parse(const string& _str, const uint32_t flags) { - if (! parser.get()) - throw_(parse_error, "Value expression parser not initialized"); - + parser_t parser; str = _str; - ptr = parser->parse(str, flags); + ptr = parser.parse(str, flags); compiled = false; } void expr_t::parse(std::istream& in, const uint32_t flags, const string * original_string) { - if (! parser.get()) - throw_(parse_error, "Value expression parser not initialized"); - + parser_t parser; str = "<stream>"; - ptr = parser->parse(in, flags, original_string); + ptr = parser.parse(in, flags, original_string); compiled = false; } @@ -131,7 +123,18 @@ value_t expr_t::calc(scope_t& scope) dump(*_log_stream); } } - return ptr->calc(scope); + + ptr_op_t context; + try { + return ptr->calc(scope, &context); + } + catch (const std::exception& err) { + if (context) { + add_error_context("While evaluating value expression:"); + add_error_context(op_context(ptr, context)); + } + throw; + } } return NULL_VALUE; } @@ -182,16 +185,6 @@ void expr_t::dump(std::ostream& out) const if (ptr) ptr->dump(out, 0); } -void expr_t::initialize() -{ - parser.reset(new expr_t::parser_t); -} - -void expr_t::shutdown() -{ - parser.reset(); -} - std::ostream& operator<<(std::ostream& out, const expr_t& expr) { expr.print(out); return out; |