mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 04:25:13 +00:00
LibJS: Move logical not operator to new unary expression class
This commit is contained in:
parent
65343388b8
commit
5e817ee678
Notes:
sideshowbarker
2024-07-19 08:48:53 +09:00
Author: https://github.com/0xtechnobabble Commit: https://github.com/SerenityOS/serenity/commit/5e817ee6783 Pull-request: https://github.com/SerenityOS/serenity/pull/1397 Reviewed-by: https://github.com/sunverwerth
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
Reference in a new issue