mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 03:07:44 +00:00
LibJS: Move logical not operator to new unary expression class
This commit is contained in:
parent
65343388b8
commit
5e817ee678
2 changed files with 7 additions and 22 deletions
|
@ -210,17 +210,12 @@ Value LogicalExpression::execute(Interpreter& interpreter) const
|
|||
{
|
||||
auto lhs_result = m_lhs->execute(interpreter).as_bool();
|
||||
|
||||
if (m_op == LogicalOp::Not)
|
||||
return Value(!lhs_result);
|
||||
|
||||
auto rhs_result = m_rhs->execute(interpreter).as_bool();
|
||||
switch (m_op) {
|
||||
case LogicalOp::And:
|
||||
return Value(lhs_result && rhs_result);
|
||||
case LogicalOp::Or:
|
||||
return Value(lhs_result || rhs_result);
|
||||
case LogicalOp::Not:
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
|
||||
ASSERT_NOT_REACHED();
|
||||
|
@ -232,6 +227,8 @@ Value UnaryExpression::execute(Interpreter& interpreter) const
|
|||
switch (m_op) {
|
||||
case UnaryOp::BitNot:
|
||||
return bit_not(lhs_result);
|
||||
case UnaryOp::Not:
|
||||
return Value(!lhs_result.as_bool());
|
||||
}
|
||||
|
||||
ASSERT_NOT_REACHED();
|
||||
|
@ -313,14 +310,6 @@ void LogicalExpression::dump(int indent) const
|
|||
case LogicalOp::Or:
|
||||
op_string = "||";
|
||||
break;
|
||||
case LogicalOp::Not:
|
||||
op_string = "!";
|
||||
print_indent(indent);
|
||||
printf("%s\n", class_name());
|
||||
print_indent(indent + 1);
|
||||
printf("%s\n", op_string);
|
||||
m_lhs->dump(indent + 1);
|
||||
return;
|
||||
}
|
||||
|
||||
print_indent(indent);
|
||||
|
@ -338,6 +327,9 @@ void UnaryExpression::dump(int indent) const
|
|||
case UnaryOp::BitNot:
|
||||
op_string = "~";
|
||||
break;
|
||||
case UnaryOp::Not:
|
||||
op_string = "!";
|
||||
break;
|
||||
}
|
||||
|
||||
print_indent(indent);
|
||||
|
|
|
@ -209,7 +209,6 @@ private:
|
|||
enum class LogicalOp {
|
||||
And,
|
||||
Or,
|
||||
Not
|
||||
};
|
||||
|
||||
class LogicalExpression : public Expression {
|
||||
|
@ -221,13 +220,6 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
LogicalExpression(LogicalOp op, NonnullOwnPtr<Expression> lhs)
|
||||
: m_op(op)
|
||||
, m_lhs(move(lhs))
|
||||
{
|
||||
ASSERT(op == LogicalOp::Not);
|
||||
}
|
||||
|
||||
virtual Value execute(Interpreter&) const override;
|
||||
virtual void dump(int indent) const override;
|
||||
|
||||
|
@ -236,11 +228,12 @@ private:
|
|||
|
||||
LogicalOp m_op;
|
||||
NonnullOwnPtr<Expression> m_lhs;
|
||||
OwnPtr<Expression> m_rhs;
|
||||
NonnullOwnPtr<Expression> m_rhs;
|
||||
};
|
||||
|
||||
enum class UnaryOp {
|
||||
BitNot,
|
||||
Not,
|
||||
};
|
||||
|
||||
class UnaryExpression : public Expression {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue