mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 18:38:10 +00:00
JSSpecCompiler: Recurse into the correct subtrees in RecursiveASTVisitor
RecursiveASTVisitor was recursing into the subtrees of an old root if it was changed in on_entry callback. Fix that by querying root pointer just after on_entry callback returns. While on it, also use `AK::TemporaryChange` instead of setting `m_current_subtree_pointer` manually. As it turns out, `FunctionCallCanonicalizationPass` was relying on being able to replace tree on entry, and the bug in RecursiveASTVisitor made the pass to not fully canonicalize nested function calls. The changes to GenericASTPass.cpp alone are enough to fix the problem but it is canonical (for some definition of canonicity) to only change trees in on_leave. Therefore, the commit also switches FunctionCallCanonicalizationPass to on_leave callback. A test for this fix and one from the previous commit is also included.
This commit is contained in:
parent
33b36476d9
commit
b4a9fde756
6 changed files with 77 additions and 9 deletions
|
@ -9,9 +9,9 @@
|
|||
|
||||
namespace JSSpecCompiler {
|
||||
|
||||
RecursionDecision FunctionCallCanonicalizationPass::on_entry(Tree tree)
|
||||
void FunctionCallCanonicalizationPass::on_leave(Tree tree)
|
||||
{
|
||||
if (auto binary_operation = as<BinaryOperation>(tree); binary_operation) {
|
||||
if (auto binary_operation = as<BinaryOperation>(tree)) {
|
||||
if (binary_operation->m_operation == BinaryOperator::FunctionCall) {
|
||||
Vector<Tree> arguments;
|
||||
|
||||
|
@ -33,7 +33,6 @@ RecursionDecision FunctionCallCanonicalizationPass::on_entry(Tree tree)
|
|||
replace_current_node_with(make_ref_counted<FunctionCall>(binary_operation->m_left, move(arguments)));
|
||||
}
|
||||
}
|
||||
return RecursionDecision::Recurse;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue