mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 04:47:35 +00:00
LibJS: Implement if statements
If statements execute a certain action or an alternative one depending on whether the tested condition is true or false, this commit helps establish basic control flow capabilities in the AST.
This commit is contained in:
parent
a96bf2c22e
commit
b6307beb6e
2 changed files with 47 additions and 0 deletions
|
@ -127,6 +127,30 @@ private:
|
|||
NonnullOwnPtr<Expression> m_argument;
|
||||
};
|
||||
|
||||
class IfStatement : public ASTNode {
|
||||
public:
|
||||
explicit IfStatement(NonnullOwnPtr<Expression> predicate, NonnullOwnPtr<ScopeNode> consequent, NonnullOwnPtr<ScopeNode> alternate)
|
||||
: m_predicate(move(predicate))
|
||||
, m_consequent(move(consequent))
|
||||
, m_alternate(move(alternate))
|
||||
{
|
||||
}
|
||||
|
||||
const Expression& predicate() const { return *m_predicate; }
|
||||
const ScopeNode& consequent() const { return *m_consequent; }
|
||||
const ScopeNode& alternate() const { return *m_alternate; }
|
||||
|
||||
virtual Value execute(Interpreter&) const override;
|
||||
virtual void dump(int indent) const override;
|
||||
|
||||
private:
|
||||
virtual const char* class_name() const override { return "IfStatement"; }
|
||||
|
||||
NonnullOwnPtr<Expression> m_predicate;
|
||||
NonnullOwnPtr<ScopeNode> m_consequent;
|
||||
NonnullOwnPtr<ScopeNode> m_alternate;
|
||||
};
|
||||
|
||||
enum class BinaryOp {
|
||||
Plus,
|
||||
Minus,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue