summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibCpp/Parser.h
diff options
context:
space:
mode:
authorItamar <itamar8910@gmail.com>2021-04-02 13:57:52 +0300
committerAndreas Kling <kling@serenityos.org>2021-04-06 21:51:58 +0200
commite16036b9cca4e22cdf3c4a316c1a8b3a37fc6d9f (patch)
tree6480fe166d1ef2b82d2e218084752add45c9fcc1 /Userland/Libraries/LibCpp/Parser.h
parentaa717e6a62a6dc18d10482ea03937568c90ebb8c (diff)
downloadserenity-e16036b9cca4e22cdf3c4a316c1a8b3a37fc6d9f.zip
LibCpp: Introduce DummyASTNode
This allows us to use pase_* methods inside match_* methods, without adding any actual AST nodes to the m_nodes list.
Diffstat (limited to 'Userland/Libraries/LibCpp/Parser.h')
-rw-r--r--Userland/Libraries/LibCpp/Parser.h16
1 files changed, 13 insertions, 3 deletions
diff --git a/Userland/Libraries/LibCpp/Parser.h b/Userland/Libraries/LibCpp/Parser.h
index 0fff5f685d..94961e6968 100644
--- a/Userland/Libraries/LibCpp/Parser.h
+++ b/Userland/Libraries/LibCpp/Parser.h
@@ -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;
};