IfBranchMergingPass.h 796 B

123456789101112131415161718192021222324252627282930313233343536
  1. /*
  2. * Copyright (c) 2023, Dan Klishch <danilklishch@gmail.com>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include "Compiler/GenericASTPass.h"
  8. namespace JSSpecCompiler {
  9. // IfBranchMergingPass, unsurprisingly, merges if-elseif-else chains, represented as a separate
  10. // nodes after parsing, into one IfElseIfChain node. It also deals with the following nonsense from
  11. // the spec:
  12. // ```
  13. // 1. If <condition>, then
  14. // ...
  15. // 2. Else,
  16. // a. If <condition>, then
  17. // ...
  18. // 3. Else,
  19. // ...
  20. // ```
  21. class IfBranchMergingPass : public GenericASTPass {
  22. public:
  23. using GenericASTPass::GenericASTPass;
  24. protected:
  25. RecursionDecision on_entry(Tree tree) override;
  26. private:
  27. static Tree merge_branches(Vector<Tree> const& unmerged_branches);
  28. };
  29. }