mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 05:08:13 +00:00
JSSpecCompiler: Allow storing NullableTree
s in nodes
And use this in ElseIfBranch node.
This commit is contained in:
parent
4eede5282c
commit
092ed1cc8a
7 changed files with 56 additions and 18 deletions
|
@ -8,6 +8,29 @@
|
|||
|
||||
namespace JSSpecCompiler {
|
||||
|
||||
Tree NodeSubtreePointer::get(Badge<RecursiveASTVisitor>)
|
||||
{
|
||||
return m_tree_ptr.visit(
|
||||
[&](NullableTree* nullable_tree) -> Tree {
|
||||
NullableTree copy = *nullable_tree;
|
||||
return copy.release_nonnull();
|
||||
},
|
||||
[&](Tree* tree) -> Tree {
|
||||
return *tree;
|
||||
});
|
||||
}
|
||||
|
||||
void NodeSubtreePointer::replace_subtree(Badge<RecursiveASTVisitor>, NullableTree replacement)
|
||||
{
|
||||
m_tree_ptr.visit(
|
||||
[&](NullableTree* nullable_tree) {
|
||||
*nullable_tree = replacement;
|
||||
},
|
||||
[&](Tree* tree) {
|
||||
*tree = replacement.release_nonnull();
|
||||
});
|
||||
}
|
||||
|
||||
Vector<NodeSubtreePointer> BinaryOperation::subtrees()
|
||||
{
|
||||
return { { &m_left }, { &m_right } };
|
||||
|
@ -43,8 +66,8 @@ Vector<NodeSubtreePointer> IfBranch::subtrees()
|
|||
|
||||
Vector<NodeSubtreePointer> ElseIfBranch::subtrees()
|
||||
{
|
||||
if (m_condition.has_value())
|
||||
return { { &m_condition.value() }, { &m_branch } };
|
||||
if (m_condition)
|
||||
return { { &m_condition }, { &m_branch } };
|
||||
return { { &m_branch } };
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue