Replace all make_pair calls with initializer lists

This commit is contained in:
Matthias Schiffer 2015-04-18 19:25:22 +02:00
parent 96d6221449
commit 30c2141182
11 changed files with 34 additions and 34 deletions

View file

@ -72,7 +72,7 @@ public:
} }
void add_arg(const std::string &str, const std::string &name, bool func = false) { 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) {} function_t(const std::string &type, const std::string &name) : type_name({type + ' ' + name, name}, true) {}

View file

@ -87,7 +87,7 @@ void generator_t::generate() {
item_t shifted = item; item_t shifted = item;
shifted.shift(); shifted.shift();
std::set<item_t> &set = new_sets.insert(std::make_pair(sym, empty_set)).first->second; std::set<item_t> &set = new_sets.insert({sym, empty_set}).first->second;
set.insert(std::move(shifted)); 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; item_t rule = grammar.rules[i].item;
nonterminals.insert(rule.get_lhs()); nonterminals.insert(rule.get_lhs());
nonterms.insert(std::make_pair(rule.get_lhs(), i)); nonterms.insert({rule.get_lhs(), i});
while (rule.has_next()) { while (rule.has_next()) {
const symbol_t &sym = rule.get_next_symbol(); 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) if (sym.get_type() != SYMBOL_TYPE_NONTERM)
terminals.insert(sym); terminals.insert(sym);
@ -134,7 +134,7 @@ generator_t::generator_t(const grammar_t &grammar0) : grammar(grammar0) {
rule.shift(); rule.shift();
} }
rule_ids.insert(std::make_pair(rule, i)); rule_ids.insert({rule, i});
} }
} }

View file

@ -63,18 +63,18 @@ private:
std::set<item_t> get_set(const std::string &nonterm); std::set<item_t> get_set(const std::string &nonterm);
std::pair<std::map<std::set<item_t>, size_t>::iterator, bool> add_set(const std::set<item_t> &set) { std::pair<std::map<std::set<item_t>, size_t>::iterator, bool> add_set(const std::set<item_t> &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) { void add_shift(size_t from, const symbol_t &sym, size_t to) {
if (has_reduce_conflict(from, sym)) if (has_reduce_conflict(from, sym))
throw conflict_error("shift/reduce conflict"); 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) { 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: protected:

View file

@ -39,11 +39,11 @@ void generator_lr0_t::add_reduction(size_t from, size_t rule) {
throw conflict_error("reduce/reduce conflict"); throw conflict_error("reduce/reduce conflict");
for (const symbol_t &sym : get_terminals()) { 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"); throw conflict_error("shift/reduce conflict");
} }
reductions.insert(std::make_pair(from, rule)); reductions.insert({from, rule});
} }
} }

View file

@ -33,7 +33,7 @@ void generator_slr_t::generate_first_sets() {
std::set<item_t> items; std::set<item_t> items;
for (const std::string &nonterm : get_nonterminals()) for (const std::string &nonterm : get_nonterminals())
first_sets.insert(std::make_pair(nonterm, std::set<symbol_t>())); first_sets.insert({nonterm, std::set<symbol_t>()});
for (const rule_t &rule : get_grammar().rules) for (const rule_t &rule : get_grammar().rules)
items.insert(rule.item); items.insert(rule.item);
@ -74,7 +74,7 @@ void generator_slr_t::generate_follow_sets() {
generate_first_sets(); generate_first_sets();
for (const std::string &nonterm : get_nonterminals()) for (const std::string &nonterm : get_nonterminals())
follow_sets.insert(std::make_pair(nonterm, std::set<symbol_t>())); follow_sets.insert({nonterm, std::set<symbol_t>()});
follow_sets[""].insert(symbol_t::empty()); 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) { 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) { void generator_slr_t::add_reduction(size_t from, size_t rule) {
const item_t &item = get_grammar().rules[rule].item; const item_t &item = get_grammar().rules[rule].item;
for (const symbol_t sym : follow_sets[item.get_lhs()]) { 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"); 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"); throw conflict_error("reduce/reduce conflict");
} }
} }

View file

@ -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) : 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) { generator(generator0), prefix(prefix0), token_prefix(token_prefix0) {
for (const std::string &nonterm : generator->get_nonterminals()) 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()) { for (const symbol_t &term : generator->get_terminals()) {
if (term.get_type() == SYMBOL_TYPE_TERM) 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});
} }
} }

View file

@ -49,7 +49,7 @@ void output_header_t::emit_token_value() {
for (const symbol_t &term : get_generator()->get_terminals()) { for (const symbol_t &term : get_generator()->get_terminals()) {
const auto &type = get_generator()->get_grammar().get_term_type(term); const auto &type = get_generator()->get_grammar().get_term_type(term);
if (!type.first.empty()) 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) for (const auto &value : token_values)

View file

@ -142,11 +142,11 @@ void output_source_t::emit_gotos(const std::string &lhs) {
std::map<unsigned, std::set<unsigned>> gotos; std::map<unsigned, std::set<unsigned>> gotos;
for (size_t state = 0; state < get_generator()->get_state_count(); state++) { 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()) if (it == get_generator()->get_gotos().end())
continue; continue;
std::set<unsigned> &states = gotos.insert(std::make_pair(it->second, std::set<unsigned>())).first->second; std::set<unsigned> &states = gotos.insert({it->second, std::set<unsigned>()}).first->second;
states.insert(state); states.insert(state);
} }

View file

@ -33,11 +33,11 @@ void output_source_slr_t::emit_state_shift(unsigned state) {
std::map<unsigned, std::set<symbol_t>> shifts; std::map<unsigned, std::set<symbol_t>> shifts;
for (const symbol_t &token : get_generator()->get_terminals()) { 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()) if (it == get_generator()->get_shifts().end())
continue; continue;
std::set<symbol_t> &symbols = shifts.insert(std::make_pair(it->second, std::set<symbol_t>())).first->second; std::set<symbol_t> &symbols = shifts.insert({it->second, std::set<symbol_t>()}).first->second;
symbols.insert(token); symbols.insert(token);
} }
@ -92,11 +92,11 @@ bool output_source_slr_t::emit_state_reduce(unsigned state) {
std::map<unsigned, std::set<symbol_t>> reductions; std::map<unsigned, std::set<symbol_t>> reductions;
for (const symbol_t &token : get_generator()->get_terminals()) { 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()) if (it == get_generator()->get_reductions().end())
continue; continue;
std::set<symbol_t> &symbols = reductions.insert(std::make_pair(it->second, std::set<symbol_t>())).first->second; std::set<symbol_t> &symbols = reductions.insert({it->second, std::set<symbol_t>()}).first->second;
symbols.insert(token); 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) { void output_source_slr_t::emit_state(unsigned state) {
block_t switch_token(this, "switch (token)"); 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_case(0);
write_line_("return 0"); write_line_("return 0");
write_line(); write_line();

View file

@ -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) { 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) { 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) { 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<std::string> *ns, __attribute__((unused)) grammar_t *grammar) { static inline void parse_reduce_6(std::vector<std::string> *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) { 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) { static inline void parse_reduce_10(std::string *lhs, rhs_t *rhs, std::string *action, __attribute__((unused)) grammar_t *grammar) {

View file

@ -41,15 +41,15 @@ grammar |= grammar directive;
directive |= "%type" SYMBOL(nonterm) BLOCK(type) { 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) { 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) { directive |= "%destructor" symbol(sym) csymbol(name) {
grammar->destructors.insert(std::make_pair(*sym, *name)); grammar->destructors.insert({*sym, *name});
} }
directive |= "%namespace" namespace(ns) { directive |= "%namespace" namespace(ns) {
@ -65,7 +65,7 @@ directive |= "%header" BLOCK(block) {
} }
directive |= "%extra_arg" BLOCK(type) csymbol(name) { 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) { directive |= SYMBOL(lhs) "|=" rhs(rhs) action(action) {