From 915978aa9d3a3717b517f21074c0cb4e461aa057 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Thu, 24 May 2018 16:22:16 -0700 Subject: [PATCH] Avoid redundant logging of conflicting tokens --- .../build_tables/lex_table_builder.cc | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/src/compiler/build_tables/lex_table_builder.cc b/src/compiler/build_tables/lex_table_builder.cc index 54957efe..001dbc81 100644 --- a/src/compiler/build_tables/lex_table_builder.cc +++ b/src/compiler/build_tables/lex_table_builder.cc @@ -265,9 +265,11 @@ class LexTableBuilderImpl : public LexTableBuilder { } private: - void record_conflict(Symbol shadowed_token, Symbol other_token, ConflictStatus status) { + bool record_conflict(Symbol shadowed_token, Symbol other_token, ConflictStatus status) { unsigned index = shadowed_token.index * grammar.variables.size() + other_token.index; + bool old_value = conflict_matrix[index] & status; conflict_matrix[index] = static_cast(conflict_matrix[index] | status); + return old_value; } LexStateId add_lex_state(LexTable &lex_table, const LexItemSet &item_set) { @@ -313,29 +315,31 @@ class LexTableBuilderImpl : public LexTableBuilder { CharacterSet conflicting_following_chars = characters.intersection(following_chars); CharacterSet conflicting_sep_chars = characters.intersection(separator_start_characters); if (!conflicting_following_chars.is_empty()) { - LOG( - "%s shadows %s followed by '%s'", - token_name(advance_symbol).c_str(), - token_name(accept_action.symbol).c_str(), - log_char(*conflicting_following_chars.included_chars.begin()) - ); - record_conflict( + if (record_conflict( accept_action.symbol, advance_symbol, MatchesLongerStringWithValidNextChar - ); + )) { + LOG( + "%s shadows %s followed by '%s'", + token_name(advance_symbol).c_str(), + token_name(accept_action.symbol).c_str(), + log_char(*conflicting_following_chars.included_chars.begin()) + ); + } } else if (!conflicting_sep_chars.is_empty()) { - LOG( - "%s shadows %s followed by '%s'", - token_name(advance_symbol).c_str(), - token_name(accept_action.symbol).c_str(), - log_char(*conflicting_sep_chars.included_chars.begin()) - ); - record_conflict( + if (record_conflict( accept_action.symbol, advance_symbol, MatchesLongerStringWithValidNextChar - ); + )) { + LOG( + "%s shadows %s followed by '%s'", + token_name(advance_symbol).c_str(), + token_name(accept_action.symbol).c_str(), + log_char(*conflicting_sep_chars.included_chars.begin()) + ); + } } else { record_conflict(accept_action.symbol, advance_symbol, MatchesLongerString); }