IfBranchMergingPass.h 866 B

1234567891011121314151617181920212223242526272829303132333435363738
  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. inline static constexpr StringView name = "if-branch-merging"sv;
  24. using GenericASTPass::GenericASTPass;
  25. protected:
  26. RecursionDecision on_entry(Tree tree) override;
  27. private:
  28. static Tree merge_branches(Vector<Tree> const& unmerged_branches);
  29. };
  30. }