diff --git a/src/log_surgeon/Buffer.hpp b/src/log_surgeon/Buffer.hpp index 2a35195..de51c36 100644 --- a/src/log_surgeon/Buffer.hpp +++ b/src/log_surgeon/Buffer.hpp @@ -72,8 +72,8 @@ class Buffer { // Currently needed for compression [[nodiscard]] auto get_mutable_active_buffer() -> Item* { return m_active_storage; } - void - copy(Item const* storage_to_copy_first, Item const* storage_to_copy_last, uint32_t offset) { + auto copy(Item const* storage_to_copy_first, Item const* storage_to_copy_last, uint32_t offset) + -> void { std::copy(storage_to_copy_first, storage_to_copy_last, m_active_storage + offset); } diff --git a/src/log_surgeon/Lalr1Parser.tpp b/src/log_surgeon/Lalr1Parser.tpp index 79bfc47..a000c8e 100644 --- a/src/log_surgeon/Lalr1Parser.tpp +++ b/src/log_surgeon/Lalr1Parser.tpp @@ -66,40 +66,39 @@ Lalr1Parser::Lalr1Parser() { } template -void Lalr1Parser::add_rule( +auto Lalr1Parser::add_rule( std::string const& name, std::unique_ptr> rule -) { +) -> void { Parser::add_rule(name, std::move(rule)); m_terminals.insert(m_lexer.m_symbol_id[name]); } template -void Lalr1Parser::add_token_group( +auto Lalr1Parser::add_token_group( std::string const& name, std::unique_ptr> rule_group -) { +) -> void { add_rule(name, std::move(rule_group)); } template -void Lalr1Parser::add_token_chain( +auto Lalr1Parser::add_token_chain( std::string const& name, std::string const& chain -) { +) -> void { assert(chain.size() > 1); - std::unique_ptr> first_char_rule + auto first_char_rule = std::make_unique>(chain[0]); - std::unique_ptr> second_char_rule + auto second_char_rule = std::make_unique>(chain[1]); - std::unique_ptr> rule_chain - = std::make_unique>( - std::move(first_char_rule), - std::move(second_char_rule) - ); + auto rule_chain = std::make_unique>( + std::move(first_char_rule), + std::move(second_char_rule) + ); for (uint32_t i = 2; i < chain.size(); i++) { - char next_char = chain[i]; - std::unique_ptr> next_char_rule + auto next_char = chain[i]; + auto next_char_rule = std::make_unique>(next_char); rule_chain = std::make_unique>( std::move(rule_chain), @@ -151,7 +150,7 @@ auto Lalr1Parser::add_production( } template -void Lalr1Parser::generate() { +auto Lalr1Parser::generate() -> void { m_lexer.generate(); assert(!m_productions.empty()); generate_lr0_kernels(); @@ -161,28 +160,28 @@ void Lalr1Parser::generate() { } template -void Lalr1Parser::generate_lr0_kernels() { - Production* root_production_ptr = m_productions[m_root_production_id].get(); +auto Lalr1Parser::generate_lr0_kernels() -> void { + auto* root_production_ptr = m_productions[m_root_production_id].get(); Item root_item(root_production_ptr, 0, cNullSymbol); - std::unique_ptr item_set0 = std::make_unique(); + auto item_set0 = std::make_unique(); item_set0->m_kernel.insert(root_item); std::deque unused_item_sets; item_set0->m_index = m_lr0_item_sets.size(); unused_item_sets.push_back(item_set0.get()); m_lr0_item_sets[item_set0->m_kernel] = std::move(item_set0); while (!unused_item_sets.empty()) { - ItemSet* item_set_ptr = unused_item_sets.back(); + auto* item_set_ptr = unused_item_sets.back(); unused_item_sets.pop_back(); generate_lr0_closure(item_set_ptr); - for (uint32_t const& next_symbol : m_terminals) { - ItemSet* new_item_set_ptr = go_to(item_set_ptr, next_symbol); + for (auto const& next_symbol : m_terminals) { + auto* new_item_set_ptr = go_to(item_set_ptr, next_symbol); if (new_item_set_ptr != nullptr) { unused_item_sets.push_back(new_item_set_ptr); } } - for (std::map>::value_type const& kv : m_non_terminals) { - uint32_t next_symbol = kv.first; - ItemSet* new_item_set_ptr = go_to(item_set_ptr, next_symbol); + for (auto const& kv : m_non_terminals) { + auto next_symbol = kv.first; + auto* new_item_set_ptr = go_to(item_set_ptr, next_symbol); if (new_item_set_ptr != nullptr) { unused_item_sets.push_back(new_item_set_ptr); } @@ -211,13 +210,14 @@ auto Lalr1Parser::lr_closure_helper( } template -void Lalr1Parser::generate_lr0_closure(ItemSet* item_set_ptr) { +auto Lalr1Parser::generate_lr0_closure(ItemSet* item_set_ptr +) -> void { std::deque q( item_set_ptr->m_kernel.begin(), item_set_ptr->m_kernel.end() ); // {{S'->(dot)S, ""}} while (!q.empty()) { - Item item = q.back(); // {S'->(dot)S, ""} + auto item = q.back(); // {S'->(dot)S, ""} q.pop_back(); uint32_t next_symbol = 0; if (lr_closure_helper(item_set_ptr, &item, &next_symbol)) { @@ -238,9 +238,9 @@ auto Lalr1Parser::go_to( ItemSet* from_item_set, uint32_t const& next_symbol ) -> ItemSet* { - std::unique_ptr next_item_set_ptr = std::make_unique(); + auto next_item_set_ptr = std::make_unique(); assert(from_item_set != nullptr); - for (Item const& item : from_item_set->m_closure) { + for (auto const& item : from_item_set->m_closure) { if (item.has_dot_at_end()) { continue; } @@ -253,7 +253,7 @@ auto Lalr1Parser::go_to( return nullptr; } if (m_lr0_item_sets.find(next_item_set_ptr->m_kernel) != m_lr0_item_sets.end()) { - ItemSet* existing_item_set_ptr = m_lr0_item_sets[next_item_set_ptr->m_kernel].get(); + auto* existing_item_set_ptr = m_lr0_item_sets[next_item_set_ptr->m_kernel].get(); m_go_to_table[from_item_set->m_index][next_symbol] = existing_item_set_ptr->m_index; from_item_set->m_next[next_symbol] = existing_item_set_ptr; } else { @@ -267,23 +267,23 @@ auto Lalr1Parser::go_to( } template -void Lalr1Parser::generate_first_sets() { +auto Lalr1Parser::generate_first_sets() -> void { for (uint32_t const& s : m_terminals) { m_firsts.insert(std::pair>(s, {s})); } bool changed = true; while (changed) { changed = false; - for (std::unique_ptr const& p : m_productions) { - std::set& f = m_firsts[p->m_head]; + for (auto const& p : m_productions) { + auto& f = m_firsts[p->m_head]; if (p->is_epsilon()) { changed = changed || m_nullable.insert(p->m_head).second; continue; } - size_t old = f.size(); + auto old = f.size(); size_t i = 0; - for (uint32_t const& s : p->m_body) { - std::set& f2 = m_firsts[s]; + for (auto const& s : p->m_body) { + auto& f2 = m_firsts[s]; f.insert(f2.begin(), f2.end()); if (m_nullable.find(s) == m_nullable.end()) { break; @@ -299,14 +299,13 @@ void Lalr1Parser::generate_first_sets() { } template -void Lalr1Parser::generate_lr1_item_sets() { - for (std::map, std::unique_ptr>::value_type const& kv : m_lr0_item_sets) - { - for (Item const& l0_item : kv.second->m_kernel) { +auto Lalr1Parser::generate_lr1_item_sets() -> void { + for (auto const& kv : m_lr0_item_sets) { + for (auto const& l0_item : kv.second->m_kernel) { ItemSet temp_item_set; temp_item_set.m_kernel.insert(l0_item); generate_lr1_closure(&temp_item_set); - for (Item const& l1_item : temp_item_set.m_closure) { + for (auto const& l1_item : temp_item_set.m_closure) { if (l1_item.m_lookahead != cNullSymbol) { m_spontaneous_map[l1_item.m_production].insert(l1_item.m_lookahead); } else { @@ -319,9 +318,8 @@ void Lalr1Parser::generate_lr1_item_sets() { } } std::map> lookaheads; - for (std::map, std::unique_ptr>::value_type const& kv : m_lr0_item_sets) - { - for (Item const& l0_item : kv.second->m_kernel) { + for (auto const& kv : m_lr0_item_sets) { + for (auto const& l0_item : kv.second->m_kernel) { lookaheads[l0_item].insert( m_spontaneous_map[l0_item.m_production].begin(), m_spontaneous_map[l0_item.m_production].end() @@ -334,24 +332,23 @@ void Lalr1Parser::generate_lr1_item_sets() { bool changed = true; while (changed) { changed = false; - for (std::map>::value_type& kv : m_propagate_map) { - Item item_from = kv.first; - for (Item const& item_to : kv.second) { - size_t size_before = lookaheads[item_to].size(); + for (auto& kv : m_propagate_map) { + auto item_from = kv.first; + for (auto const& item_to : kv.second) { + auto size_before = lookaheads[item_to].size(); lookaheads[item_to].insert( lookaheads[item_from].begin(), lookaheads[item_from].end() ); - size_t size_after = lookaheads[item_to].size(); + auto size_after = lookaheads[item_to].size(); changed = changed || size_after > size_before; } } } - for (std::map, std::unique_ptr>::value_type const& kv : m_lr0_item_sets) - { - std::unique_ptr lr1_item_set_ptr = std::make_unique(); - for (Item const& l0_item : kv.second->m_kernel) { - for (int const& lookahead : lookaheads[l0_item]) { + for (auto const& kv : m_lr0_item_sets) { + auto lr1_item_set_ptr = std::make_unique(); + for (auto const& l0_item : kv.second->m_kernel) { + for (auto const lookahead : lookaheads[l0_item]) { Item lr1_item(l0_item.m_production, l0_item.m_dot, lookahead); lr1_item_set_ptr->m_kernel.insert(lr1_item); } @@ -366,13 +363,9 @@ void Lalr1Parser::generate_lr1_item_sets() { m_lr1_item_sets[lr1_item_set_ptr->m_kernel] = std::move(lr1_item_set_ptr); } // this seems like the wrong way to do this still: - for (std::map, std::unique_ptr>::value_type const& kv1 : - m_lr1_item_sets) - { + for (auto const& kv1 : m_lr1_item_sets) { for (auto const& next_index : m_go_to_table[kv1.second->m_index]) { - for (std::map, std::unique_ptr>::value_type const& kv2 : - m_lr1_item_sets) - { + for (auto const& kv2 : m_lr1_item_sets) { if (next_index.second == kv2.second->m_index) { kv1.second->m_next[next_index.first] = kv2.second.get(); break; @@ -383,20 +376,21 @@ void Lalr1Parser::generate_lr1_item_sets() { } template -void Lalr1Parser::generate_lr1_closure(ItemSet* item_set_ptr) { +auto Lalr1Parser::generate_lr1_closure(ItemSet* item_set_ptr +) -> void { std::deque queue(item_set_ptr->m_kernel.begin(), item_set_ptr->m_kernel.end()); while (!queue.empty()) { - Item item = queue.back(); + auto item = queue.back(); queue.pop_back(); uint32_t next_symbol = 0; if (lr_closure_helper(item_set_ptr, &item, &next_symbol)) { continue; } std::vector lookaheads; - size_t pos = item.m_dot + 1; + auto pos = item.m_dot + 1; while (pos < item.m_production->m_body.size()) { - uint32_t symbol = item.m_production->m_body.at(pos); - std::set symbol_firsts = m_firsts.find(symbol)->second; + auto symbol = item.m_production->m_body.at(pos); + auto symbol_firsts = m_firsts.find(symbol)->second; lookaheads.insert( lookaheads.end(), std::make_move_iterator(symbol_firsts.begin()), @@ -410,8 +404,8 @@ void Lalr1Parser::generate_lr1_closure(ItemSet* it if (pos == item.m_production->m_body.size()) { lookaheads.push_back(item.m_lookahead); } - for (Production* const p : m_non_terminals.at(next_symbol)) { - for (uint32_t const& l : lookaheads) { + for (auto* const p : m_non_terminals.at(next_symbol)) { + for (auto const l : lookaheads) { queue.emplace_back(p, 0, l); } } @@ -419,24 +413,23 @@ void Lalr1Parser::generate_lr1_closure(ItemSet* it } template -void Lalr1Parser::generate_lalr1_parsing_table() { +auto Lalr1Parser::generate_lalr1_parsing_table() -> void { generate_lalr1_goto(); generate_lalr1_action(); } template -void Lalr1Parser::generate_lalr1_goto() { +auto Lalr1Parser::generate_lalr1_goto() -> void { // done already at end of generate_lr1_item_sets()? } // Dragon book page 253 template -void Lalr1Parser::generate_lalr1_action() { - for (std::map, std::unique_ptr>::value_type const& kv : m_lr1_item_sets) - { - ItemSet* item_set_ptr = kv.second.get(); +auto Lalr1Parser::generate_lalr1_action() -> void { + for (auto const& kv : m_lr1_item_sets) { + auto* item_set_ptr = kv.second.get(); item_set_ptr->m_actions.resize(m_lexer.m_symbol_id.size(), false); - for (Item const& item : item_set_ptr->m_closure) { + for (auto const& item : item_set_ptr->m_closure) { if (!item.has_dot_at_end()) { if (m_terminals.find(item.next_symbol()) == m_terminals.end() && m_non_terminals.find(item.next_symbol()) == m_non_terminals.end()) @@ -444,7 +437,7 @@ void Lalr1Parser::generate_lalr1_action() { continue; } assert(item_set_ptr->m_next.find(item.next_symbol()) != item_set_ptr->m_next.end()); - Action& action = item_set_ptr->m_actions[item.next_symbol()]; + auto& action = item_set_ptr->m_actions[item.next_symbol()]; if (!std::holds_alternative(action)) { if (std::holds_alternative(action) && std::get(action) == item_set_ptr->m_next[item.next_symbol()]) @@ -481,7 +474,7 @@ void Lalr1Parser::generate_lalr1_action() { Action action = true; item_set_ptr->m_actions[(uint32_t)SymbolId::TokenEnd] = action; } else { - Action& action = item_set_ptr->m_actions[item.m_lookahead]; + auto& action = item_set_ptr->m_actions[item.m_lookahead]; if (!std::holds_alternative(action)) { std::string conflict_msg{}; conflict_msg += "For symbol "; @@ -523,7 +516,7 @@ auto Lalr1Parser::get_input_after_last_newline( std::string error_message_reversed; bool done = false; while (!parse_stack_matches.empty() && !done) { - MatchedSymbol top_symbol = std::move(parse_stack_matches.top()); + MatchedSymbol top_symbol{std::move(parse_stack_matches.top())}; parse_stack_matches.pop(); std::visit( Overloaded{ @@ -534,7 +527,7 @@ auto Lalr1Parser::get_input_after_last_newline( // input is being read backwards, so reverse // each token so that when the entire input is // reversed each token is displayed correctly - std::string token_string = token.to_string(); + auto token_string = token.to_string(); std::reverse(token_string.begin(), token_string.end()); error_message_reversed += token_string; } @@ -563,7 +556,7 @@ auto Lalr1Parser::get_input_until_next_newline(Tok bool next_has_newline = (error_token->to_string().find('\n') != std::string::npos) || (error_token->to_string().find('\r') != std::string::npos); while (!next_has_newline && !next_is_end_token) { - Token token = get_next_symbol(); + auto token = get_next_symbol(); next_has_newline = (token.to_string().find('\n') != std::string::npos) || (token.to_string().find('\r') != std::string::npos); if (!next_has_newline) { @@ -579,15 +572,15 @@ template auto Lalr1Parser::report_error() -> std::string { assert(m_next_token == std::nullopt); assert(!m_parse_stack_matches.empty()); - MatchedSymbol top_symbol = std::move(m_parse_stack_matches.top()); + MatchedSymbol top_symbol{std::move(m_parse_stack_matches.top())}; m_parse_stack_matches.pop(); - uint32_t line_num = get_line_num(top_symbol); - Token token = std::get(top_symbol); - std::string consumed_input = get_input_after_last_newline(m_parse_stack_matches); + auto line_num = get_line_num(top_symbol); + auto token = std::get(top_symbol); + auto consumed_input = get_input_after_last_newline(m_parse_stack_matches); std::string error_type{}; std::string error_indicator; - Token error_token = token; - std::string rest_of_line = get_input_until_next_newline(&error_token); + auto error_token = token; + auto rest_of_line = get_input_until_next_newline(&error_token); for (uint32_t i = 0; i < consumed_input.size() + 10; i++) { error_indicator += " "; } @@ -598,7 +591,7 @@ auto Lalr1Parser::report_error() -> std::string { } else { error_type = "expected "; for (uint32_t i = 0; i < m_parse_stack_states.top()->m_actions.size(); i++) { - Action action = m_parse_stack_states.top()->m_actions[i]; + auto action = m_parse_stack_states.top()->m_actions[i]; if (action.index() != 0) { error_type += "'"; if (auto* regex_ast_literal @@ -616,9 +609,9 @@ auto Lalr1Parser::report_error() -> std::string { error_type.pop_back(); error_type += " before '" + unescape(token.to_string()[0]) + "' token"; } - std::string error_string = "Schema:" + std::to_string(line_num + 1) + ":" - + std::to_string(consumed_input.size() + 1) - + ": error: " + error_type + "\n"; + auto error_string = "Schema:" + std::to_string(line_num + 1) + ":" + + std::to_string(consumed_input.size() + 1) + ": error: " + error_type + + "\n"; for (int i = 0; i < 10; i++) { error_string += " "; } @@ -633,7 +626,7 @@ auto Lalr1Parser::parse(Reader& reader) -> NonTerm bool accept = false; while (true) { m_input_buffer.read_if_safe(reader); - Token next_terminal = get_next_symbol(); + auto next_terminal = get_next_symbol(); if (parse_advance(next_terminal, &accept)) { break; } @@ -642,14 +635,14 @@ auto Lalr1Parser::parse(Reader& reader) -> NonTerm throw std::runtime_error(report_error()); } assert(!m_parse_stack_matches.empty()); - MatchedSymbol m = std::move(m_parse_stack_matches.top()); + MatchedSymbol m{std::move(m_parse_stack_matches.top())}; m_parse_stack_matches.pop(); assert(m_parse_stack_matches.empty()); return std::move(std::get(m)); } template -void Lalr1Parser::reset() { +auto Lalr1Parser::reset() -> void { m_next_token = std::nullopt; while (!m_parse_stack_states.empty()) { m_parse_stack_states.pop(); @@ -665,12 +658,12 @@ template auto Lalr1Parser::get_next_symbol() -> Token { if (m_next_token == std::nullopt) { Token token; - if (ErrorCode error = m_lexer.scan(m_input_buffer, token); ErrorCode::Success != error) { + if (auto error = m_lexer.scan(m_input_buffer, token); ErrorCode::Success != error) { throw std::runtime_error("Error scanning in lexer."); } return token; } - Token s = m_next_token.value(); + auto s = m_next_token.value(); m_next_token = std::nullopt; return s; } @@ -695,8 +688,8 @@ auto Lalr1Parser::parse_symbol( Token& next_token, bool* accept ) -> bool { - ItemSet* curr = m_parse_stack_states.top(); - Action& it = curr->m_actions[type_id]; + auto* curr = m_parse_stack_states.top(); + auto& it = curr->m_actions[type_id]; bool ret = false; std::visit( Overloaded{ @@ -718,7 +711,7 @@ auto Lalr1Parser::parse_symbol( [&ret, &next_token, this](Production* reduce) { m_next_token = next_token; NonTerminal matched_non_terminal(reduce); - size_t n = reduce->m_body.size(); + auto n = reduce->m_body.size(); for (size_t i = 0; i < n; i++) { m_parse_stack_states.pop(); assert((matched_non_terminal.m_children_start + n - i - 1) @@ -739,9 +732,8 @@ auto Lalr1Parser::parse_symbol( matched_non_terminal.m_ast = reduce->m_semantic_rule(&matched_non_terminal); } - ItemSet* curr = m_parse_stack_states.top(); - Action const& it - = curr->m_actions[matched_non_terminal.m_production->m_head]; + auto* curr = m_parse_stack_states.top(); + auto const& it = curr->m_actions[matched_non_terminal.m_production->m_head]; m_parse_stack_states.push(std::get(it)); m_parse_stack_matches.emplace(std::move(matched_non_terminal)); ret = true; diff --git a/src/log_surgeon/Lexer.tpp b/src/log_surgeon/Lexer.tpp index 7310a1c..dded278 100644 --- a/src/log_surgeon/Lexer.tpp +++ b/src/log_surgeon/Lexer.tpp @@ -18,7 +18,7 @@ */ namespace log_surgeon { template -void Lexer::flip_states(uint32_t old_storage_size) { +auto Lexer::flip_states(uint32_t old_storage_size) -> void { if (m_match_pos >= old_storage_size / 2) { m_match_pos -= old_storage_size / 2; } else { @@ -41,7 +41,7 @@ void Lexer::flip_states(uint32_t old_storage_size) template auto Lexer::scan(ParserInputBuffer& input_buffer, Token& token) -> ErrorCode { - TypedDfaState const* state = m_dfa->get_root(); + auto const* state = m_dfa->get_root(); if (m_asked_for_more_data) { state = m_prev_state; m_asked_for_more_data = false; @@ -65,9 +65,10 @@ auto Lexer::scan(ParserInputBuffer& input_buffer, m_type_ids = nullptr; } while (true) { - uint32_t prev_byte_buf_pos = input_buffer.storage().pos(); - unsigned char next_char{utf8::cCharErr}; - if (ErrorCode err = input_buffer.get_next_character(next_char); ErrorCode::Success != err) { + auto prev_byte_buf_pos = input_buffer.storage().pos(); + auto next_char{utf8::cCharErr}; + if (auto const err = input_buffer.get_next_character(next_char); ErrorCode::Success != err) + { m_asked_for_more_data = true; m_prev_state = state; return err; @@ -80,7 +81,7 @@ auto Lexer::scan(ParserInputBuffer& input_buffer, m_match_pos = prev_byte_buf_pos; m_match_line = m_line; } - TypedDfaState* next = state->next(next_char); + auto* next = state->next(next_char); if (next_char == '\n') { m_line++; if (m_has_delimiters && !m_match) { @@ -172,7 +173,7 @@ auto Lexer::scan_with_wildcard( char wildcard, Token& token ) -> ErrorCode { - TypedDfaState const* state = m_dfa->get_root(); + auto const* state = m_dfa->get_root(); if (m_asked_for_more_data) { state = m_prev_state; m_asked_for_more_data = false; @@ -196,7 +197,7 @@ auto Lexer::scan_with_wildcard( m_type_ids = nullptr; } while (true) { - uint32_t prev_byte_buf_pos = input_buffer.storage().pos(); + auto prev_byte_buf_pos = input_buffer.storage().pos(); unsigned char next_char{utf8::cCharErr}; if (ErrorCode err = input_buffer.get_next_character(next_char); ErrorCode::Success != err) { m_asked_for_more_data = true; @@ -239,7 +240,7 @@ auto Lexer::scan_with_wildcard( // BFS (keep track of m_type_ids) if (wildcard == '?') { for (uint32_t byte = 0; byte < cSizeOfByte; byte++) { - TypedDfaState* next_state = state->next(byte); + auto* next_state = state->next(byte); if (next_state->is_accepting() == false) { token = Token{m_last_match_pos, @@ -345,10 +346,10 @@ template void Lexer::add_delimiters(std::vector const& delimiters) { assert(!delimiters.empty()); m_has_delimiters = true; - for (bool& i : m_is_delimiter) { + for (auto& i : m_is_delimiter) { i = false; } - for (uint32_t delimiter : delimiters) { + for (auto delimiter : delimiters) { m_is_delimiter[delimiter] = true; } m_is_delimiter[utf8::cCharStartOfFile] = true; @@ -378,7 +379,7 @@ void Lexer::generate() { finite_automata::Nfa nfa{std::move(m_rules)}; // TODO: DFA ignores tags. E.g., treats "capture:user=(?\d+)" as "capture:user=\d+" m_dfa = nfa_to_dfa(nfa); - TypedDfaState const* state = m_dfa->get_root(); + auto const* state = m_dfa->get_root(); for (uint32_t i = 0; i < cSizeOfByte; i++) { if (state->next(i) != nullptr) { m_is_first_char[i] = true; @@ -429,23 +430,22 @@ template auto Lexer::nfa_to_dfa(finite_automata::Nfa& nfa ) -> std::unique_ptr> { typedef std::set StateSet; - std::unique_ptr> dfa - = std::make_unique>(); + auto dfa = std::make_unique>(); std::map dfa_states; std::stack unmarked_sets; auto create_dfa_state = [&dfa, &dfa_states, &unmarked_sets](StateSet const& set) -> TypedDfaState* { - TypedDfaState* state = dfa->new_state(set); + auto* state = dfa->new_state(set); dfa_states[set] = state; unmarked_sets.push(set); return state; }; - StateSet start_set = epsilon_closure(nfa.get_root()); + auto start_set = epsilon_closure(nfa.get_root()); create_dfa_state(start_set); while (!unmarked_sets.empty()) { - StateSet set = unmarked_sets.top(); + auto set = unmarked_sets.top(); unmarked_sets.pop(); - TypedDfaState* dfa_state = dfa_states.at(set); + auto* dfa_state = dfa_states.at(set); std::map ascii_transitions_map; for (TypedNfaState const* s0 : set) { for (uint32_t i = 0; i < cSizeOfByte; i++) { @@ -467,7 +467,7 @@ auto Lexer::nfa_to_dfa(finite_automata::Nfa::value_type const& kv : ascii_transitions_map) { - TypedDfaState* dest_state = next_dfa_state(kv.second); + auto* dest_state = next_dfa_state(kv.second); dfa_state->add_byte_transition(kv.first, dest_state); } } diff --git a/src/log_surgeon/LogEvent.cpp b/src/log_surgeon/LogEvent.cpp index 709e62c..8a3deea 100644 --- a/src/log_surgeon/LogEvent.cpp +++ b/src/log_surgeon/LogEvent.cpp @@ -42,7 +42,7 @@ auto LogEventView::reset() -> void { start = 1; } for (uint32_t i = start; i < m_log_output_buffer->pos(); i++) { - Token& token = m_log_output_buffer->get_mutable_token(i); + auto& token = m_log_output_buffer->get_mutable_token(i); raw_log += token.to_string_view(); } return raw_log; @@ -51,7 +51,7 @@ auto LogEventView::reset() -> void { auto LogEventView::get_logtype() const -> std::string { std::string logtype; for (uint32_t i = 1; i < m_log_output_buffer->pos(); i++) { - Token& token = m_log_output_buffer->get_mutable_token(i); + auto& token = m_log_output_buffer->get_mutable_token(i); if (token.m_type_ids_ptr->at(0) == (uint32_t)SymbolId::TokenUncaughtString) { logtype += token.to_string_view(); } else { diff --git a/src/log_surgeon/LogParser.cpp b/src/log_surgeon/LogParser.cpp index 89d3abf..ab7cde5 100644 --- a/src/log_surgeon/LogParser.cpp +++ b/src/log_surgeon/LogParser.cpp @@ -43,7 +43,7 @@ auto LogParser::add_delimiters(unique_ptr const& delimiters) -> void } } -void LogParser::add_rules(std::unique_ptr schema_ast) { +auto LogParser::add_rules(std::unique_ptr schema_ast) -> void { for (auto const& delimiters : schema_ast->m_delimiters) { add_delimiters(delimiters); } diff --git a/src/log_surgeon/Parser.tpp b/src/log_surgeon/Parser.tpp index 4747072..6a4da16 100644 --- a/src/log_surgeon/Parser.tpp +++ b/src/log_surgeon/Parser.tpp @@ -30,10 +30,10 @@ Parser::Parser() { } template -void Parser::add_rule( +auto Parser::add_rule( std::string const& name, std::unique_ptr> rule -) { +) -> void { if (m_lexer.m_symbol_id.find(name) == m_lexer.m_symbol_id.end()) { m_lexer.m_symbol_id[name] = m_lexer.m_symbol_id.size(); m_lexer.m_id_symbol[m_lexer.m_symbol_id[name]] = name; @@ -42,7 +42,8 @@ void Parser::add_rule( } template -void Parser::add_token(std::string const& name, char rule_char) { +auto Parser::add_token(std::string const& name, char rule_char) + -> void { add_rule(name, std::make_unique>(rule_char)); } } // namespace log_surgeon diff --git a/src/log_surgeon/ParserInputBuffer.cpp b/src/log_surgeon/ParserInputBuffer.cpp index 15fde34..8fdb70b 100644 --- a/src/log_surgeon/ParserInputBuffer.cpp +++ b/src/log_surgeon/ParserInputBuffer.cpp @@ -9,7 +9,7 @@ using std::string; using std::to_string; namespace log_surgeon { -void ParserInputBuffer::reset() { +auto ParserInputBuffer::reset() -> void { m_log_fully_consumed = false; m_finished_reading_input = false; m_pos_last_read_char = 0; @@ -107,12 +107,12 @@ auto ParserInputBuffer::get_next_character(unsigned char& next_char) -> ErrorCod // the user to wrap their input buffer. It tricks the LogParser and // ParserInputBuffer into thinking it never reaches the wrap, while still // respecting the actual size of the buffer the user passed in. -void ParserInputBuffer::set_storage( +auto ParserInputBuffer::set_storage( char* storage, uint32_t size, uint32_t pos, bool finished_reading_input -) { +) -> void { reset(); m_storage.set_active_buffer(storage, size * 2, pos); m_finished_reading_input = finished_reading_input; diff --git a/src/log_surgeon/Schema.cpp b/src/log_surgeon/Schema.cpp index e2008b1..dd4b086 100644 --- a/src/log_surgeon/Schema.cpp +++ b/src/log_surgeon/Schema.cpp @@ -11,7 +11,7 @@ Schema::Schema(std::string const& schema_file_path) : m_schema_ast{SchemaParser::try_schema_file(schema_file_path)} {} auto Schema::add_variable(std::string_view const var_schema, int const priority) const -> void { - std::unique_ptr const schema_ast = SchemaParser::try_schema_string(var_schema); + auto const schema_ast = SchemaParser::try_schema_string(var_schema); m_schema_ast->add_schema_var(std::move(schema_ast->m_schema_vars[0]), priority); } } // namespace log_surgeon diff --git a/src/log_surgeon/SchemaParser.cpp b/src/log_surgeon/SchemaParser.cpp index 3c7bd2c..d36271c 100644 --- a/src/log_surgeon/SchemaParser.cpp +++ b/src/log_surgeon/SchemaParser.cpp @@ -416,7 +416,7 @@ static auto new_delimiter_string_rule(NonTerminal* m) -> unique_ptr { return make_unique(character); } -void SchemaParser::add_lexical_rules() { +auto SchemaParser::add_lexical_rules() -> void { if (m_special_regex_characters.empty()) { m_special_regex_characters.emplace('(', "Lparen"); m_special_regex_characters.emplace(')', "Rparen"); @@ -481,7 +481,7 @@ void SchemaParser::add_lexical_rules() { add_token_group("CommentCharacters", std::move(comment_characters)); } -void SchemaParser::add_productions() { +auto SchemaParser::add_productions() -> void { // add_production("Schema", {}, new_schema_rule); add_production("Schema", {"Comment"}, new_schema_rule); add_production("Schema", {"SchemaVar"}, new_schema_rule_with_var);