diff --git a/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/AST/AST.cpp b/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/AST/AST.cpp index 239070b1a1..60037c941d 100644 --- a/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/AST/AST.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/AST/AST.cpp @@ -83,10 +83,22 @@ Vector IfElseIfChain::subtrees() return result; } +TreeList::TreeList(Vector&& trees) +{ + for (auto const& tree : trees) { + if (tree->is_list()) { + for (auto const& nested_tree : as(tree)->m_trees) + m_trees.append(nested_tree); + } else { + m_trees.append(tree); + } + } +} + Vector TreeList::subtrees() { Vector result; - for (auto& expression : m_expressions) + for (auto& expression : m_trees) result.append({ &expression }); return result; } diff --git a/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/AST/AST.h b/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/AST/AST.h index 2f3eac95ce..4b72da89ab 100644 --- a/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/AST/AST.h +++ b/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/AST/AST.h @@ -59,7 +59,7 @@ public: // For expressions, order must be the same as the evaluation order. virtual Vector subtrees() { return {}; } - virtual bool is_type() { return false; } + virtual bool is_list() const { return false; } protected: template @@ -372,14 +372,13 @@ protected: class TreeList : public Statement { public: - TreeList(Vector&& expressions_) - : m_expressions(move(expressions_)) - { - } + TreeList(Vector&& trees); Vector subtrees() override; - Vector m_expressions; + bool is_list() const override { return true; } + + Vector m_trees; protected: void dump_tree(StringBuilder& builder) override; diff --git a/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/AST/ASTPrinting.cpp b/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/AST/ASTPrinting.cpp index fd963a82a6..87a27cc0be 100644 --- a/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/AST/ASTPrinting.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/AST/ASTPrinting.cpp @@ -129,7 +129,7 @@ void IfElseIfChain::dump_tree(StringBuilder& builder) void TreeList::dump_tree(StringBuilder& builder) { dump_node(builder, "TreeList"); - for (auto const& expression : m_expressions) + for (auto const& expression : m_trees) expression->format_tree(builder); } diff --git a/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Compiler/IfBranchMergingPass.cpp b/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Compiler/IfBranchMergingPass.cpp index 6f83613a9d..ad97c0ae23 100644 --- a/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Compiler/IfBranchMergingPass.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Compiler/IfBranchMergingPass.cpp @@ -24,7 +24,7 @@ RecursionDecision IfBranchMergingPass::on_entry(Tree tree) } }; - for (auto const& node : list->m_expressions) { + for (auto const& node : list->m_trees) { if (is(node.ptr())) { merge_if_needed(); unmerged_branches.append(node); @@ -37,7 +37,7 @@ RecursionDecision IfBranchMergingPass::on_entry(Tree tree) } merge_if_needed(); - list->m_expressions = move(result); + list->m_trees = move(result); } return RecursionDecision::Recurse; } @@ -75,8 +75,8 @@ Tree IfBranchMergingPass::merge_branches(Vector const& unmerged_branches) // 3. Else, // ... auto substep_list = as(branch->m_branch); - if (substep_list && substep_list->m_expressions.size() == 1) { - if (auto nested_if = as(substep_list->m_expressions[0]); nested_if) + if (substep_list && substep_list->m_trees.size() == 1) { + if (auto nested_if = as(substep_list->m_trees[0]); nested_if) branch = make_ref_counted(nested_if->m_condition, nested_if->m_branch); } }