1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 23:47:43 +00:00

JSSpecCompiler: Add if branch merging pass

It merges standalone IfBranch/ElseIfBranch nodes into IfElseIfChain
nodes. This will ease CFG generation later.
This commit is contained in:
Dan Klishch 2023-08-18 21:16:53 -04:00 committed by Andrew Kaster
parent 092ed1cc8a
commit 4c4e1e1aed
8 changed files with 184 additions and 0 deletions

View file

@ -0,0 +1,36 @@
/*
* Copyright (c) 2023, Dan Klishch <danilklishch@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include "Compiler/GenericASTPass.h"
namespace JSSpecCompiler {
// IfBranchMergingPass, unsurprisingly, merges if-elseif-else chains, represented as a separate
// nodes after parsing, into one IfElseIfChain node. It also deals with the following nonsense from
// the spec:
// ```
// 1. If <condition>, then
// ...
// 2. Else,
// a. If <condition>, then
// ...
// 3. Else,
// ...
// ```
class IfBranchMergingPass : public GenericASTPass {
public:
using GenericASTPass::GenericASTPass;
protected:
RecursionDecision on_entry(Tree tree) override;
private:
static Tree merge_branches(Vector<Tree> const& unmerged_branches);
};
}