mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:17:45 +00:00
JSSpecCompiler: Restrict usage of NodeSubtreePointer
This class stores a non-owning raw pointer to a member of `Node`, so extra care is needed to ensure that referenced `Node`s will be alive by the time `NodeSubtreePointer` is used. Since we only need to use this class while traversing AST in `RecursiveASTVisitor`, access to class methods can be restricted using `Badge<RecursiveASTVisitor>`.
This commit is contained in:
parent
f789d26e37
commit
1c4cd34320
3 changed files with 8 additions and 4 deletions
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <AK/Badge.h>
|
||||||
#include <AK/RefCounted.h>
|
#include <AK/RefCounted.h>
|
||||||
#include <AK/RefPtr.h>
|
#include <AK/RefPtr.h>
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
|
@ -27,9 +28,9 @@ public:
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Tree& get() { return *m_tree_ptr; }
|
Tree& get(Badge<RecursiveASTVisitor>) { return *m_tree_ptr; }
|
||||||
|
|
||||||
void replace_subtree(Tree tree) { *m_tree_ptr = move(tree); }
|
void replace_subtree(Badge<RecursiveASTVisitor>, Tree tree) { *m_tree_ptr = move(tree); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Tree* m_tree_ptr;
|
Tree* m_tree_ptr;
|
||||||
|
|
|
@ -18,7 +18,7 @@ void RecursiveASTVisitor::run_in_subtree(Tree& tree)
|
||||||
|
|
||||||
void RecursiveASTVisitor::replace_current_node_with(Tree tree)
|
void RecursiveASTVisitor::replace_current_node_with(Tree tree)
|
||||||
{
|
{
|
||||||
m_current_subtree_pointer->replace_subtree(move(tree));
|
m_current_subtree_pointer->replace_subtree({}, move(tree));
|
||||||
}
|
}
|
||||||
|
|
||||||
RecursionDecision RecursiveASTVisitor::recurse(Tree root, NodeSubtreePointer& pointer)
|
RecursionDecision RecursiveASTVisitor::recurse(Tree root, NodeSubtreePointer& pointer)
|
||||||
|
@ -30,7 +30,7 @@ RecursionDecision RecursiveASTVisitor::recurse(Tree root, NodeSubtreePointer& po
|
||||||
|
|
||||||
if (decision == RecursionDecision::Recurse) {
|
if (decision == RecursionDecision::Recurse) {
|
||||||
for (auto& child : root->subtrees()) {
|
for (auto& child : root->subtrees()) {
|
||||||
if (recurse(child.get(), child) == RecursionDecision::Break)
|
if (recurse(child.get({}), child) == RecursionDecision::Break)
|
||||||
return RecursionDecision::Break;
|
return RecursionDecision::Break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,9 @@ class Variable;
|
||||||
class FunctionPointer;
|
class FunctionPointer;
|
||||||
using FunctionPointerRef = NonnullRefPtr<FunctionPointer>;
|
using FunctionPointerRef = NonnullRefPtr<FunctionPointer>;
|
||||||
|
|
||||||
|
// Compiler/GenericASTPass.h
|
||||||
|
class RecursiveASTVisitor;
|
||||||
|
|
||||||
// Parser/SpecParser.h
|
// Parser/SpecParser.h
|
||||||
class AlgorithmStep;
|
class AlgorithmStep;
|
||||||
class AlgorithmStepList;
|
class AlgorithmStepList;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue