From e95e8c3f792c8801f5e0c31a3a2234a0ccc553e9 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Thu, 22 Jan 2009 18:53:44 -0400 Subject: Corrected a parse-time optimization of "! CONSTANT". --- src/parser.cc | 2 +- src/value.cc | 29 +++++++++++++++++++++++++++++ src/value.h | 1 + 3 files changed, 31 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/parser.cc b/src/parser.cc index d54d78cd..f47a76db 100644 --- a/src/parser.cc +++ b/src/parser.cc @@ -117,7 +117,7 @@ expr_t::parser_t::parse_unary_expr(std::istream& in, // A very quick optimization if (term->kind == op_t::VALUE) { - term->as_value_lval().in_place_negate(); + term->as_value_lval().in_place_not(); node = term; } else { node = new op_t(op_t::O_NOT); diff --git a/src/value.cc b/src/value.cc index 7db334cb..1ebc3110 100644 --- a/src/value.cc +++ b/src/value.cc @@ -1237,6 +1237,35 @@ void value_t::in_place_negate() throw_(value_error, "Cannot negate " << label()); } +void value_t::in_place_not() +{ + switch (type()) { + case BOOLEAN: + set_boolean(! as_boolean()); + return; + case INTEGER: + case DATETIME: + set_boolean(! as_long()); + return; + case DATE: + set_boolean(! as_long()); + return; + case AMOUNT: + set_boolean(! as_amount()); + return; + case BALANCE: + set_boolean(! as_balance()); + return; + case BALANCE_PAIR: + set_boolean(! as_balance_pair()); + return; + default: + break; + } + + throw_(value_error, "Cannot not " << label()); +} + bool value_t::is_realzero() const { switch (type()) { diff --git a/src/value.h b/src/value.h index 0afd6404..5c55a117 100644 --- a/src/value.h +++ b/src/value.h @@ -400,6 +400,7 @@ public: return temp; } void in_place_negate(); // exists for efficiency's sake + void in_place_not(); // exists for efficiency's sake value_t operator-() const { return negate(); -- cgit v1.2.3