Corrected a parse-time optimization of "! CONSTANT".
This commit is contained in:
parent
965df4a404
commit
e95e8c3f79
3 changed files with 31 additions and 1 deletions
|
|
@ -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);
|
||||
|
|
|
|||
29
src/value.cc
29
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()) {
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue