From c397e030f40e9126b98eb3c203daeb40d00fef40 Mon Sep 17 00:00:00 2001 From: Federico Guerinoni Date: Mon, 17 May 2021 22:14:59 +0200 Subject: [PATCH] LibCpp: Add function for retrieving TODO comments from the parser Now `get_todo_entries` collects all TODO found within a comment statement. --- Userland/Libraries/LibCpp/Parser.cpp | 13 +++++++++++++ Userland/Libraries/LibCpp/Parser.h | 1 + 2 files changed, 14 insertions(+) diff --git a/Userland/Libraries/LibCpp/Parser.cpp b/Userland/Libraries/LibCpp/Parser.cpp index 0eee97958a..c4b913ef6a 100644 --- a/Userland/Libraries/LibCpp/Parser.cpp +++ b/Userland/Libraries/LibCpp/Parser.cpp @@ -961,6 +961,19 @@ void Parser::print_tokens() const } } +Vector Parser::get_todo_entries() const +{ + Vector ret; + for (auto& token : m_tokens) { + if (token.type() == Token::Type::Comment) { + if (token.text().contains("TODO")) { + ret.append(token.text()); + } + } + } + return ret; +} + NonnullRefPtr Parser::parse_string_literal(ASTNode& parent) { ScopeLogger logger; diff --git a/Userland/Libraries/LibCpp/Parser.h b/Userland/Libraries/LibCpp/Parser.h index 22e294fbf0..1ac0226151 100644 --- a/Userland/Libraries/LibCpp/Parser.h +++ b/Userland/Libraries/LibCpp/Parser.h @@ -35,6 +35,7 @@ public: void print_tokens() const; const Vector& errors() const { return m_state.errors; } const Preprocessor::Definitions& preprocessor_definitions() const { return m_preprocessor_definitions; } + Vector get_todo_entries() const; struct TokenAndPreprocessorDefinition { Token token;