mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 20:37:36 +00:00
LibCpp: Introduce DummyASTNode
This allows us to use pase_* methods inside match_* methods, without adding any actual AST nodes to the m_nodes list.
This commit is contained in:
parent
aa717e6a62
commit
e16036b9cc
3 changed files with 38 additions and 16 deletions
|
@ -155,6 +155,7 @@ private:
|
|||
struct State {
|
||||
size_t token_index { 0 };
|
||||
Vector<String> errors;
|
||||
NonnullRefPtrVector<ASTNode> nodes;
|
||||
};
|
||||
|
||||
void error(StringView message = {});
|
||||
|
@ -164,7 +165,9 @@ private:
|
|||
create_ast_node(ASTNode& parent, const Position& start, Optional<Position> end, Args&&... args)
|
||||
{
|
||||
auto node = adopt(*new T(&parent, start, end, m_filename, forward<Args>(args)...));
|
||||
m_nodes.append(node);
|
||||
if(!parent.is_dummy_node()) {
|
||||
m_state.nodes.append(node);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
|
@ -172,11 +175,19 @@ private:
|
|||
create_root_ast_node(const Position& start, Position end)
|
||||
{
|
||||
auto node = adopt(*new TranslationUnit(nullptr, start, end, m_filename));
|
||||
m_nodes.append(node);
|
||||
m_state.nodes.append(node);
|
||||
m_root_node = node;
|
||||
return node;
|
||||
}
|
||||
|
||||
|
||||
DummyAstNode& get_dummy_node()
|
||||
{
|
||||
static NonnullRefPtr<DummyAstNode> dummy = adopt(*new DummyAstNode(nullptr, {}, {}, {}));
|
||||
return dummy;
|
||||
}
|
||||
|
||||
|
||||
bool match_attribute_specification();
|
||||
void consume_attribute_specification();
|
||||
bool match_ellipsis();
|
||||
|
@ -191,7 +202,6 @@ private:
|
|||
State m_state;
|
||||
Vector<State> m_saved_states;
|
||||
RefPtr<TranslationUnit> m_root_node;
|
||||
NonnullRefPtrVector<ASTNode> m_nodes;
|
||||
|
||||
Vector<TokenAndPreprocessorDefinition> m_replaced_preprocessor_tokens;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue