From c5017ab7afb48aaf0af64b98df7043b89d4beac5 Mon Sep 17 00:00:00 2001 From: Sharaf Mohamed Date: Tue, 7 Jan 2025 06:55:54 -0500 Subject: [PATCH] refactor: Update NFA and DFA headers to align with the latest coding guidelines. (#58) Co-authored-by: Lin Zhihao <59785146+LinZhihao-723@users.noreply.github.com> --- src/log_surgeon/LALR1Parser.cpp | 4 ++-- src/log_surgeon/LALR1Parser.hpp | 4 ++-- .../finite_automata/RegexDFAState.hpp | 21 ++++++++++--------- .../finite_automata/RegexDFAStatePair.hpp | 21 +++++++++---------- src/log_surgeon/finite_automata/RegexNFA.hpp | 3 --- .../finite_automata/RegexNFAState.hpp | 5 ++--- 6 files changed, 27 insertions(+), 31 deletions(-) diff --git a/src/log_surgeon/LALR1Parser.cpp b/src/log_surgeon/LALR1Parser.cpp index 5268091d..d1c4b7c0 100644 --- a/src/log_surgeon/LALR1Parser.cpp +++ b/src/log_surgeon/LALR1Parser.cpp @@ -8,9 +8,9 @@ ParserAST::~ParserAST() = default; uint32_t NonTerminal::m_next_children_start = 0; NonTerminal::NonTerminal(Production* p) - : m_children_start(NonTerminal::m_next_children_start), + : m_children_start(m_next_children_start), m_production(p), m_ast(nullptr) { - NonTerminal::m_next_children_start += p->m_body.size(); + m_next_children_start += p->m_body.size(); } } // namespace log_surgeon diff --git a/src/log_surgeon/LALR1Parser.hpp b/src/log_surgeon/LALR1Parser.hpp index c31e78e0..f4e7f91a 100644 --- a/src/log_surgeon/LALR1Parser.hpp +++ b/src/log_surgeon/LALR1Parser.hpp @@ -77,7 +77,7 @@ class NonTerminal { */ [[nodiscard]] auto token_cast(uint32_t i) const -> Token* { assert(i < cSizeOfAllChildren); - return &std::get(NonTerminal::m_all_children[m_children_start + i]); + return &std::get(m_all_children[m_children_start + i]); } /** @@ -89,7 +89,7 @@ class NonTerminal { */ [[nodiscard]] auto non_terminal_cast(uint32_t i) const -> NonTerminal* { assert(i < cSizeOfAllChildren); - return &std::get(NonTerminal::m_all_children[m_children_start + i]); + return &std::get(m_all_children[m_children_start + i]); } /** diff --git a/src/log_surgeon/finite_automata/RegexDFAState.hpp b/src/log_surgeon/finite_automata/RegexDFAState.hpp index 3c0ef4ca..6283e13d 100644 --- a/src/log_surgeon/finite_automata/RegexDFAState.hpp +++ b/src/log_surgeon/finite_automata/RegexDFAState.hpp @@ -19,10 +19,10 @@ class RegexDFAState; using RegexDFAByteState = RegexDFAState; using RegexDFAUTF8State = RegexDFAState; -template +template class RegexDFAState { public: - using Tree = UnicodeIntervalTree*>; + using Tree = UnicodeIntervalTree; RegexDFAState() { std::fill(std::begin(m_bytes_transition), std::end(m_bytes_transition), nullptr); @@ -40,7 +40,7 @@ class RegexDFAState { return false == m_matching_variable_ids.empty(); } - auto add_byte_transition(uint8_t const& byte, RegexDFAState* dest_state) -> void { + auto add_byte_transition(uint8_t const& byte, RegexDFAState* dest_state) -> void { m_bytes_transition[byte] = dest_state; } @@ -48,19 +48,20 @@ class RegexDFAState { * @param character The character (byte or utf8) to transition on. * @return A pointer to the DFA state reached after transitioning on `character`. */ - [[nodiscard]] auto next(uint32_t character) const -> RegexDFAState*; + [[nodiscard]] auto next(uint32_t character) const -> RegexDFAState*; private: std::vector m_matching_variable_ids; - RegexDFAState* m_bytes_transition[cSizeOfByte]; - // NOTE: We don't need m_tree_transitions for the `stateType == RegexDFAStateType::Byte` case, + RegexDFAState* m_bytes_transition[cSizeOfByte]; + // NOTE: We don't need m_tree_transitions for the `state_type == RegexDFAStateType::Byte` case, // so we use an empty class (`std::tuple<>`) in that case. - std::conditional_t> m_tree_transitions; + std::conditional_t> + m_tree_transitions; }; -template -auto RegexDFAState::next(uint32_t character) const -> RegexDFAState* { - if constexpr (RegexDFAStateType::Byte == stateType) { +template +auto RegexDFAState::next(uint32_t character) const -> RegexDFAState* { + if constexpr (RegexDFAStateType::Byte == state_type) { return m_bytes_transition[character]; } else { if (character < cSizeOfByte) { diff --git a/src/log_surgeon/finite_automata/RegexDFAStatePair.hpp b/src/log_surgeon/finite_automata/RegexDFAStatePair.hpp index 208a3e81..03d53ab9 100644 --- a/src/log_surgeon/finite_automata/RegexDFAStatePair.hpp +++ b/src/log_surgeon/finite_automata/RegexDFAStatePair.hpp @@ -27,10 +27,9 @@ class RegexDFAStatePair { m_state2(state2) {}; /** - * Used for ordering in a set by considering the states' addresses * @param rhs - * @return Whether m_state1 in lhs has a lower address than in rhs, or if they're equal, - * whether m_state2 in lhs has a lower address than in rhs + * @return Whether `m_state1` in lhs has a lower address than in rhs, or if they're equal, + * whether `m_state2` in lhs has a lower address than in rhs. */ auto operator<(RegexDFAStatePair const& rhs) const -> bool { if (m_state1 == rhs.m_state1) { @@ -41,13 +40,13 @@ class RegexDFAStatePair { /** * Generates all pairs reachable from the current pair via any string and store any reachable - * pair not previously visited in unvisited_pairs - * @param visited_pairs Previously visited pairs - * @param unvisited_pairs Set to add unvisited reachable pairs + * pair not previously visited in `unvisited_pairs`. + * @param visited_pairs Previously visited pairs. + * @param unvisited_pairs Set to add unvisited reachable pairs. */ auto get_reachable_pairs( - std::set>& visited_pairs, - std::set>& unvisited_pairs + std::set& visited_pairs, + std::set& unvisited_pairs ) const -> void; [[nodiscard]] auto is_accepting() const -> bool { @@ -65,15 +64,15 @@ class RegexDFAStatePair { template auto RegexDFAStatePair::get_reachable_pairs( - std::set>& visited_pairs, - std::set>& unvisited_pairs + std::set& visited_pairs, + std::set& unvisited_pairs ) const -> void { // TODO: Handle UTF-8 (multi-byte transitions) as well for (uint32_t i = 0; i < cSizeOfByte; i++) { auto next_state1 = m_state1->next(i); auto next_state2 = m_state2->next(i); if (next_state1 != nullptr && next_state2 != nullptr) { - RegexDFAStatePair reachable_pair{next_state1, next_state2}; + RegexDFAStatePair const reachable_pair{next_state1, next_state2}; if (visited_pairs.count(reachable_pair) == 0) { unvisited_pairs.insert(reachable_pair); } diff --git a/src/log_surgeon/finite_automata/RegexNFA.hpp b/src/log_surgeon/finite_automata/RegexNFA.hpp index ba9791b1..7e21c002 100644 --- a/src/log_surgeon/finite_automata/RegexNFA.hpp +++ b/src/log_surgeon/finite_automata/RegexNFA.hpp @@ -3,11 +3,8 @@ #include #include -#include #include -#include #include -#include #include #include #include diff --git a/src/log_surgeon/finite_automata/RegexNFAState.hpp b/src/log_surgeon/finite_automata/RegexNFAState.hpp index 8fce8cf7..c0494cb2 100644 --- a/src/log_surgeon/finite_automata/RegexNFAState.hpp +++ b/src/log_surgeon/finite_automata/RegexNFAState.hpp @@ -5,7 +5,6 @@ #include #include #include -#include #include #include #include @@ -89,8 +88,8 @@ class RegexNFAState { auto get_tree_transitions() -> Tree const& { return m_tree_transitions; } /** - Add dest_state to m_bytes_transitions if all values in interval are a byte, otherwise add - dest_state to m_tree_transitions + * Add `dest_state` to `m_bytes_transitions` if all values in interval are a byte, otherwise add + * `dest_state` to `m_tree_transitions`. * @param interval * @param dest_state */