1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 08:38:10 +00:00

JSSpecCompiler: Add infrastructure to run compiler passes on AST

This commit is contained in:
Dan Klishch 2023-08-18 13:12:20 -04:00 committed by Andrew Kaster
parent cd8f4aaa7d
commit 198591cc20
6 changed files with 243 additions and 0 deletions

View file

@ -20,6 +20,21 @@ RefPtr<T> as(NullableTree const& tree)
return dynamic_cast<T*>(tree.ptr());
}
class NodeSubtreePointer {
public:
NodeSubtreePointer(Tree* tree_ptr)
: m_tree_ptr(tree_ptr)
{
}
Tree& get() { return *m_tree_ptr; }
void replace_subtree(Tree tree) { *m_tree_ptr = move(tree); }
private:
Tree* m_tree_ptr;
};
// ===== Generic nodes =====
class Node : public RefCounted<Node> {
public:
@ -27,6 +42,9 @@ public:
void format_tree(StringBuilder& builder);
// For expressions, order must be the same as the evaluation order.
virtual Vector<NodeSubtreePointer> subtrees() { return {}; }
virtual bool is_type() { return false; }
protected:
@ -128,6 +146,8 @@ public:
{
}
Vector<NodeSubtreePointer> subtrees() override;
BinaryOperator m_operation;
Tree m_left;
Tree m_right;
@ -144,6 +164,8 @@ public:
{
}
Vector<NodeSubtreePointer> subtrees() override;
UnaryOperator m_operation;
Tree m_operand;
@ -159,6 +181,8 @@ public:
{
}
Vector<NodeSubtreePointer> subtrees() override;
Tree m_operand;
Vector<Tree> m_compare_values;
@ -186,6 +210,8 @@ public:
{
}
Vector<NodeSubtreePointer> subtrees() override;
Tree m_return_value;
protected:
@ -199,6 +225,8 @@ public:
{
}
Vector<NodeSubtreePointer> subtrees() override;
Tree m_condition;
protected:
@ -213,6 +241,8 @@ public:
{
}
Vector<NodeSubtreePointer> subtrees() override;
Tree m_condition;
Tree m_branch;
@ -228,6 +258,8 @@ public:
{
}
Vector<NodeSubtreePointer> subtrees() override;
Optional<Tree> m_condition;
Tree m_branch;
@ -242,6 +274,8 @@ public:
{
}
Vector<NodeSubtreePointer> subtrees() override;
Vector<Tree> m_expressions;
protected:
@ -261,6 +295,8 @@ public:
{
}
Vector<NodeSubtreePointer> subtrees() override;
Tree m_type_reference;
Vector<Argument> m_arguments;
@ -276,6 +312,8 @@ public:
{
}
Vector<NodeSubtreePointer> subtrees() override;
Tree m_name;
Vector<Tree> m_arguments;