From 30c2141182f4eed1d3549603a7aa92c57b35d129 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sat, 18 Apr 2015 19:25:22 +0200 Subject: Replace all make_pair calls with initializer lists --- src/codegen.hpp | 2 +- src/generator.cpp | 8 ++++---- src/generator.hpp | 6 +++--- src/generator_lr0.cpp | 4 ++-- src/generator_slr.cpp | 10 +++++----- src/output_common.cpp | 6 +++--- src/output_header.cpp | 2 +- src/output_source.cpp | 4 ++-- src/output_source_slr.cpp | 10 +++++----- src/parse.cpp | 8 ++++---- src/parse.y | 8 ++++---- 11 files changed, 34 insertions(+), 34 deletions(-) (limited to 'src') diff --git a/src/codegen.hpp b/src/codegen.hpp index 7dbfd77..1274346 100644 --- a/src/codegen.hpp +++ b/src/codegen.hpp @@ -72,7 +72,7 @@ public: } void add_arg(const std::string &str, const std::string &name, bool func = false) { - add_arg(std::make_pair(str, name), func); + add_arg({str, name}, func); } function_t(const std::string &type, const std::string &name) : type_name({type + ' ' + name, name}, true) {} diff --git a/src/generator.cpp b/src/generator.cpp index 1a4c79f..59f96b1 100644 --- a/src/generator.cpp +++ b/src/generator.cpp @@ -87,7 +87,7 @@ void generator_t::generate() { item_t shifted = item; shifted.shift(); - std::set &set = new_sets.insert(std::make_pair(sym, empty_set)).first->second; + std::set &set = new_sets.insert({sym, empty_set}).first->second; set.insert(std::move(shifted)); } @@ -122,11 +122,11 @@ generator_t::generator_t(const grammar_t &grammar0) : grammar(grammar0) { item_t rule = grammar.rules[i].item; nonterminals.insert(rule.get_lhs()); - nonterms.insert(std::make_pair(rule.get_lhs(), i)); + nonterms.insert({rule.get_lhs(), i}); while (rule.has_next()) { const symbol_t &sym = rule.get_next_symbol(); - items.insert(std::make_pair(sym, rule)); + items.insert({sym, rule}); if (sym.get_type() != SYMBOL_TYPE_NONTERM) terminals.insert(sym); @@ -134,7 +134,7 @@ generator_t::generator_t(const grammar_t &grammar0) : grammar(grammar0) { rule.shift(); } - rule_ids.insert(std::make_pair(rule, i)); + rule_ids.insert({rule, i}); } } diff --git a/src/generator.hpp b/src/generator.hpp index 0511b23..124e11b 100644 --- a/src/generator.hpp +++ b/src/generator.hpp @@ -63,18 +63,18 @@ private: std::set get_set(const std::string &nonterm); std::pair, size_t>::iterator, bool> add_set(const std::set &set) { - return itemsets.insert(std::make_pair(set, itemsets.size())); + return itemsets.insert({set, itemsets.size()}); } void add_shift(size_t from, const symbol_t &sym, size_t to) { if (has_reduce_conflict(from, sym)) throw conflict_error("shift/reduce conflict"); - shifts.insert(std::make_pair(std::make_pair(from, sym), to)); + shifts.insert({{from, sym}, to}); } void add_goto(size_t from, const std::string &nonterm, size_t to) { - gotos.insert(std::make_pair(std::make_pair(from, nonterm), to)); + gotos.insert({{from, nonterm}, to}); } protected: diff --git a/src/generator_lr0.cpp b/src/generator_lr0.cpp index a01e2d7..e2da79f 100644 --- a/src/generator_lr0.cpp +++ b/src/generator_lr0.cpp @@ -39,11 +39,11 @@ void generator_lr0_t::add_reduction(size_t from, size_t rule) { throw conflict_error("reduce/reduce conflict"); for (const symbol_t &sym : get_terminals()) { - if (get_shifts().count(std::make_pair(from, sym))) + if (get_shifts().count({from, sym})) throw conflict_error("shift/reduce conflict"); } - reductions.insert(std::make_pair(from, rule)); + reductions.insert({from, rule}); } } diff --git a/src/generator_slr.cpp b/src/generator_slr.cpp index 2989ee1..f277c5a 100644 --- a/src/generator_slr.cpp +++ b/src/generator_slr.cpp @@ -33,7 +33,7 @@ void generator_slr_t::generate_first_sets() { std::set items; for (const std::string &nonterm : get_nonterminals()) - first_sets.insert(std::make_pair(nonterm, std::set())); + first_sets.insert({nonterm, std::set()}); for (const rule_t &rule : get_grammar().rules) items.insert(rule.item); @@ -74,7 +74,7 @@ void generator_slr_t::generate_follow_sets() { generate_first_sets(); for (const std::string &nonterm : get_nonterminals()) - follow_sets.insert(std::make_pair(nonterm, std::set())); + follow_sets.insert({nonterm, std::set()}); follow_sets[""].insert(symbol_t::empty()); @@ -126,16 +126,16 @@ void generator_slr_t::generate_follow_sets() { } bool generator_slr_t::has_reduce_conflict(size_t from, const symbol_t &sym) { - return reductions.count(std::make_pair(from, sym)); + return reductions.count({from, sym}); } void generator_slr_t::add_reduction(size_t from, size_t rule) { const item_t &item = get_grammar().rules[rule].item; for (const symbol_t sym : follow_sets[item.get_lhs()]) { - if (get_shifts().count(std::make_pair(from, sym))) + if (get_shifts().count({from, sym})) throw conflict_error("shift/reduce conflict"); - if (!reductions.insert(std::make_pair(std::make_pair(from, sym), rule)).second) + if (!reductions.insert({{from, sym}, rule}).second) throw conflict_error("reduce/reduce conflict"); } } diff --git a/src/output_common.cpp b/src/output_common.cpp index a0ed757..28a2daa 100644 --- a/src/output_common.cpp +++ b/src/output_common.cpp @@ -32,13 +32,13 @@ namespace solar { output_common_t::output_common_t(const generator_t *generator0, const std::string &prefix0, const std::string &token_prefix0) : generator(generator0), prefix(prefix0), token_prefix(token_prefix0) { for (const std::string &nonterm : generator->get_nonterminals()) - symbol_values.insert(std::make_pair(symbol_t::make_nonterm(nonterm.c_str()), "symbol_" + nonterm)); + symbol_values.insert({symbol_t::make_nonterm(nonterm.c_str()), "symbol_" + nonterm}); for (const symbol_t &term : generator->get_terminals()) { if (term.get_type() == SYMBOL_TYPE_TERM) - tokens.insert(std::make_pair(token_prefix + term.get_value(), tokens.size())); + tokens.insert({token_prefix + term.get_value(), tokens.size()}); - symbol_values.insert(std::make_pair(term, "token." + generator->get_grammar().get_term_type(term).second)); + symbol_values.insert({term, "token." + generator->get_grammar().get_term_type(term).second}); } } diff --git a/src/output_header.cpp b/src/output_header.cpp index e403cfc..fe0fdf2 100644 --- a/src/output_header.cpp +++ b/src/output_header.cpp @@ -49,7 +49,7 @@ void output_header_t::emit_token_value() { for (const symbol_t &term : get_generator()->get_terminals()) { const auto &type = get_generator()->get_grammar().get_term_type(term); if (!type.first.empty()) - token_values.insert(std::make_pair(type.second, type.first)); + token_values.insert({type.second, type.first}); } for (const auto &value : token_values) diff --git a/src/output_source.cpp b/src/output_source.cpp index 576ecbc..0ae5628 100644 --- a/src/output_source.cpp +++ b/src/output_source.cpp @@ -142,11 +142,11 @@ void output_source_t::emit_gotos(const std::string &lhs) { std::map> gotos; for (size_t state = 0; state < get_generator()->get_state_count(); state++) { - auto it = get_generator()->get_gotos().find(std::make_pair(state, lhs)); + auto it = get_generator()->get_gotos().find({state, lhs}); if (it == get_generator()->get_gotos().end()) continue; - std::set &states = gotos.insert(std::make_pair(it->second, std::set())).first->second; + std::set &states = gotos.insert({it->second, std::set()}).first->second; states.insert(state); } diff --git a/src/output_source_slr.cpp b/src/output_source_slr.cpp index 420d682..1a92ba0 100644 --- a/src/output_source_slr.cpp +++ b/src/output_source_slr.cpp @@ -33,11 +33,11 @@ void output_source_slr_t::emit_state_shift(unsigned state) { std::map> shifts; for (const symbol_t &token : get_generator()->get_terminals()) { - auto it = get_generator()->get_shifts().find(std::make_pair(state, token)); + auto it = get_generator()->get_shifts().find({state, token}); if (it == get_generator()->get_shifts().end()) continue; - std::set &symbols = shifts.insert(std::make_pair(it->second, std::set())).first->second; + std::set &symbols = shifts.insert({it->second, std::set()}).first->second; symbols.insert(token); } @@ -92,11 +92,11 @@ bool output_source_slr_t::emit_state_reduce(unsigned state) { std::map> reductions; for (const symbol_t &token : get_generator()->get_terminals()) { - auto it = get_generator()->get_reductions().find(std::make_pair(state, token)); + auto it = get_generator()->get_reductions().find({state, token}); if (it == get_generator()->get_reductions().end()) continue; - std::set &symbols = reductions.insert(std::make_pair(it->second, std::set())).first->second; + std::set &symbols = reductions.insert({it->second, std::set()}).first->second; symbols.insert(token); } @@ -132,7 +132,7 @@ bool output_source_slr_t::emit_state_reduce(unsigned state) { void output_source_slr_t::emit_state(unsigned state) { block_t switch_token(this, "switch (token)"); - if (get_generator()->get_shifts().find(std::make_pair(state, symbol_t::make_nonterm(""))) != get_generator()->get_shifts().end()) { + if (get_generator()->get_shifts().find({state, symbol_t::make_nonterm("")}) != get_generator()->get_shifts().end()) { write_case(0); write_line_("return 0"); write_line(); diff --git a/src/parse.cpp b/src/parse.cpp index 0d8d417..88245bf 100644 --- a/src/parse.cpp +++ b/src/parse.cpp @@ -48,15 +48,15 @@ void parse_free(parse_context_t *parser, void (*free_func)(void *)) { static inline void parse_reduce_3(std::string *nonterm, std::string *type, __attribute__((unused)) grammar_t *grammar) { - grammar->nonterm_types.insert(std::make_pair(*nonterm, *type)); + grammar->nonterm_types.insert({*nonterm, *type}); } static inline void parse_reduce_4(symbol_t *term, std::string *type, std::string *name, __attribute__((unused)) grammar_t *grammar) { - grammar->term_types.insert(std::make_pair(*term, std::make_pair(*type, *name))); + grammar->term_types.insert({*term, {*type, *name}}); } static inline void parse_reduce_5(symbol_t *sym, std::string *name, __attribute__((unused)) grammar_t *grammar) { - grammar->destructors.insert(std::make_pair(*sym, *name)); + grammar->destructors.insert({*sym, *name}); } static inline void parse_reduce_6(std::vector *ns, __attribute__((unused)) grammar_t *grammar) { @@ -72,7 +72,7 @@ static inline void parse_reduce_8(std::string *block, __attribute__((unused)) gr } static inline void parse_reduce_9(std::string *type, std::string *name, __attribute__((unused)) grammar_t *grammar) { - grammar->extra_args.push_back(std::make_pair(*type, *name)); + grammar->extra_args.emplace_back(*type, *name); } static inline void parse_reduce_10(std::string *lhs, rhs_t *rhs, std::string *action, __attribute__((unused)) grammar_t *grammar) { diff --git a/src/parse.y b/src/parse.y index e8d26d3..db959df 100644 --- a/src/parse.y +++ b/src/parse.y @@ -41,15 +41,15 @@ grammar |= grammar directive; directive |= "%type" SYMBOL(nonterm) BLOCK(type) { - grammar->nonterm_types.insert(std::make_pair(*nonterm, *type)); + grammar->nonterm_types.insert({*nonterm, *type}); } directive |= "%type" term(term) BLOCK(type) csymbol(name) { - grammar->term_types.insert(std::make_pair(*term, std::make_pair(*type, *name))); + grammar->term_types.insert({*term, {*type, *name}}); } directive |= "%destructor" symbol(sym) csymbol(name) { - grammar->destructors.insert(std::make_pair(*sym, *name)); + grammar->destructors.insert({*sym, *name}); } directive |= "%namespace" namespace(ns) { @@ -65,7 +65,7 @@ directive |= "%header" BLOCK(block) { } directive |= "%extra_arg" BLOCK(type) csymbol(name) { - grammar->extra_args.push_back(std::make_pair(*type, *name)); + grammar->extra_args.emplace_back(*type, *name); } directive |= SYMBOL(lhs) "|=" rhs(rhs) action(action) { -- cgit v1.2.3