mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 05:17:34 +00:00
JSSpecCompiler: Add infrastructure to run compiler passes on AST
This commit is contained in:
parent
cd8f4aaa7d
commit
198591cc20
6 changed files with 243 additions and 0 deletions
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Dan Klishch <danilklishch@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/NonnullRefPtr.h>
|
||||
#include <AK/RecursionDecision.h>
|
||||
|
||||
#include "Compiler/CompilerPass.h"
|
||||
|
||||
namespace JSSpecCompiler {
|
||||
|
||||
class RecursiveASTVisitor {
|
||||
public:
|
||||
virtual ~RecursiveASTVisitor() = default;
|
||||
|
||||
void run_in_subtree(Tree& tree);
|
||||
|
||||
protected:
|
||||
virtual RecursionDecision on_entry(Tree) { return RecursionDecision::Recurse; }
|
||||
virtual void on_leave(Tree) { }
|
||||
|
||||
void replace_current_node_with(Tree tree);
|
||||
|
||||
private:
|
||||
RecursionDecision recurse(Tree root, NodeSubtreePointer& pointer);
|
||||
|
||||
NodeSubtreePointer* m_current_subtree_pointer = nullptr;
|
||||
};
|
||||
|
||||
class GenericASTPass
|
||||
: public CompilerPass
|
||||
, protected RecursiveASTVisitor {
|
||||
public:
|
||||
GenericASTPass(FunctionRef function)
|
||||
: CompilerPass(function)
|
||||
{
|
||||
}
|
||||
|
||||
void run() override;
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue