Use ::count to check if sets and maps contain elements

This commit is contained in:
Max Brunsfeld 2015-12-17 10:05:42 -08:00
parent 66144dc28e
commit 77a94a2929
4 changed files with 4 additions and 8 deletions

View file

@ -159,13 +159,9 @@ class LexTableBuilder {
void mark_fragile_tokens() {
for (LexState &state : lex_table.states)
if (state.default_action.type == LexActionTypeAccept)
if (has_fragile_token(state.default_action.symbol))
if (conflict_manager.fragile_tokens.count(state.default_action.symbol))
state.default_action.type = LexActionTypeAcceptFragile;
}
bool has_fragile_token(const Symbol &symbol) {
return conflict_manager.fragile_tokens.find(symbol) != conflict_manager.fragile_tokens.end();
}
};
LexTable build_lex_table(ParseTable *table, const LexicalGrammar &grammar) {

View file

@ -282,7 +282,7 @@ class ParseTableBuilder {
if (item.step_index > 0) {
set<Symbol> first_set = get_first_set(next_symbol);
if (first_set.find(lookahead) != first_set.end()) {
if (first_set.count(lookahead)) {
involved_symbols.insert(item.lhs());
core_shift_items.insert(item);
}

View file

@ -75,7 +75,7 @@ class LexItemTransitions : public rules::RuleFn<void> {
map<rules::MetadataKey, int> activate_precedence(
map<rules::MetadataKey, int> metadata) {
if (metadata.find(rules::PRECEDENCE) != metadata.end())
if (metadata.count(rules::PRECEDENCE))
metadata.insert({ rules::IS_ACTIVE, 1 });
return metadata;
}

View file

@ -172,7 +172,7 @@ class CCodeGenerator {
add(", ");
if (syntax_grammar.ubiquitous_tokens.find(symbol) != syntax_grammar.ubiquitous_tokens.end())
if (syntax_grammar.ubiquitous_tokens.count(symbol))
add(".extra = true");
else
add(".extra = false");