From 661314cf4eb52b8180697993b7e11c23f2fca99d Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Sun, 9 Mar 2014 22:21:58 -0700 Subject: [PATCH] Remove all non const reference parameters --- src/compiler/build_tables/item_set_closure.cc | 10 +++++----- src/compiler/generate_code/helpers.cc | 12 ++++++------ src/compiler/rules/blank.cc | 4 ++-- src/compiler/rules/blank.h | 2 +- src/compiler/rules/character_set.cc | 4 ++-- src/compiler/rules/character_set.h | 2 +- src/compiler/rules/choice.cc | 4 ++-- src/compiler/rules/choice.h | 2 +- src/compiler/rules/pattern.cc | 4 ++-- src/compiler/rules/pattern.h | 2 +- src/compiler/rules/repeat.cc | 4 ++-- src/compiler/rules/repeat.h | 2 +- src/compiler/rules/rule.h | 2 +- src/compiler/rules/seq.cc | 4 ++-- src/compiler/rules/seq.h | 2 +- src/compiler/rules/string.cc | 4 ++-- src/compiler/rules/string.h | 2 +- src/compiler/rules/symbol.cc | 4 ++-- src/compiler/rules/symbol.h | 2 +- src/compiler/rules/visitor.h | 2 +- 20 files changed, 37 insertions(+), 37 deletions(-) diff --git a/src/compiler/build_tables/item_set_closure.cc b/src/compiler/build_tables/item_set_closure.cc index 0d3d1b75..e384a6e7 100644 --- a/src/compiler/build_tables/item_set_closure.cc +++ b/src/compiler/build_tables/item_set_closure.cc @@ -10,13 +10,13 @@ namespace tree_sitter { using rules::Symbol; namespace build_tables { - static bool contains(const ParseItemSet &items, const ParseItem &item) { - return items.size() > 0 && (std::find(items.begin(), items.end(), item) != items.end()); + static bool contains(const ParseItemSet *items, const ParseItem &item) { + return items->size() > 0 && (std::find(items->begin(), items->end(), item) != items->end()); } - static void add_item(ParseItemSet &item_set, const ParseItem &item, const PreparedGrammar &grammar) { + static void add_item(ParseItemSet *item_set, const ParseItem &item, const PreparedGrammar &grammar) { if (!contains(item_set, item)) { - item_set.insert(item); + item_set->insert(item); for (auto &pair : follow_sets(item, grammar)) { Symbol non_terminal = pair.first; set terminals = pair.second; @@ -31,7 +31,7 @@ namespace tree_sitter { const ParseItemSet item_set_closure(const ParseItemSet &item_set, const PreparedGrammar &grammar) { ParseItemSet result; for (ParseItem item : item_set) - add_item(result, item, grammar); + add_item(&result, item, grammar); return result; } } diff --git a/src/compiler/generate_code/helpers.cc b/src/compiler/generate_code/helpers.cc index e8412840..ae714e8d 100644 --- a/src/compiler/generate_code/helpers.cc +++ b/src/compiler/generate_code/helpers.cc @@ -2,13 +2,13 @@ namespace tree_sitter { namespace generate_code { - static void str_replace(string &input, const string &search, const string &replace) { + static void str_replace(string *input, const string &search, const string &replace) { size_t pos = 0; while (1) { - pos = input.find(search, pos); + pos = input->find(search, pos); if (pos == string::npos) break; - input.erase(pos, search.length()); - input.insert(pos, replace); + input->erase(pos, search.length()); + input->insert(pos, replace); pos += replace.length(); } } @@ -30,12 +30,12 @@ namespace tree_sitter { string indent(string input) { string tab = " "; - str_replace(input, "\n", "\n" + tab); + str_replace(&input, "\n", "\n" + tab); return tab + input; } string escape_string(string input) { - str_replace(input, "\"", "\\\""); + str_replace(&input, "\"", "\\\""); return input; } } diff --git a/src/compiler/rules/blank.cc b/src/compiler/rules/blank.cc index e147a26b..0a499076 100644 --- a/src/compiler/rules/blank.cc +++ b/src/compiler/rules/blank.cc @@ -21,8 +21,8 @@ namespace tree_sitter { return "#"; } - void Blank::accept(Visitor &visitor) const { - visitor.visit(this); + void Blank::accept(Visitor *visitor) const { + visitor->visit(this); } } } \ No newline at end of file diff --git a/src/compiler/rules/blank.h b/src/compiler/rules/blank.h index 22528946..bdfb58e9 100644 --- a/src/compiler/rules/blank.h +++ b/src/compiler/rules/blank.h @@ -13,7 +13,7 @@ namespace tree_sitter { size_t hash_code() const; rule_ptr copy() const; std::string to_string() const; - void accept(Visitor &visitor) const; + void accept(Visitor *visitor) const; }; } } diff --git a/src/compiler/rules/character_set.cc b/src/compiler/rules/character_set.cc index 2a256617..b01a03de 100644 --- a/src/compiler/rules/character_set.cc +++ b/src/compiler/rules/character_set.cc @@ -151,8 +151,8 @@ namespace tree_sitter { return copy.remove_set(set); } - void CharacterSet::accept(Visitor &visitor) const { - visitor.visit(this); + void CharacterSet::accept(Visitor *visitor) const { + visitor->visit(this); } } } diff --git a/src/compiler/rules/character_set.h b/src/compiler/rules/character_set.h index 8037b81a..2bfa6252 100644 --- a/src/compiler/rules/character_set.h +++ b/src/compiler/rules/character_set.h @@ -19,7 +19,7 @@ namespace tree_sitter { size_t hash_code() const; rule_ptr copy() const; std::string to_string() const; - void accept(Visitor &visitor) const; + void accept(Visitor *visitor) const; void add_set(const CharacterSet &other); CharacterSet remove_set(const CharacterSet &other); diff --git a/src/compiler/rules/choice.cc b/src/compiler/rules/choice.cc index ec64fc6e..87907396 100644 --- a/src/compiler/rules/choice.cc +++ b/src/compiler/rules/choice.cc @@ -33,8 +33,8 @@ namespace tree_sitter { return string("#to_string() + " " + right->to_string() + ">"; } - void Choice::accept(Visitor &visitor) const { - visitor.visit(this); + void Choice::accept(Visitor *visitor) const { + visitor->visit(this); } } } \ No newline at end of file diff --git a/src/compiler/rules/choice.h b/src/compiler/rules/choice.h index dcbec97b..dbf6c37f 100644 --- a/src/compiler/rules/choice.h +++ b/src/compiler/rules/choice.h @@ -15,7 +15,7 @@ namespace tree_sitter { size_t hash_code() const; rule_ptr copy() const; std::string to_string() const; - void accept(Visitor &visitor) const; + void accept(Visitor *visitor) const; const rule_ptr left; const rule_ptr right; diff --git a/src/compiler/rules/pattern.cc b/src/compiler/rules/pattern.cc index 5bc0aab1..8fe3b82f 100644 --- a/src/compiler/rules/pattern.cc +++ b/src/compiler/rules/pattern.cc @@ -170,8 +170,8 @@ namespace tree_sitter { return string("#"; } - void Pattern::accept(Visitor &visitor) const { - visitor.visit(this); + void Pattern::accept(Visitor *visitor) const { + visitor->visit(this); } rule_ptr Pattern::to_rule_tree() const { diff --git a/src/compiler/rules/pattern.h b/src/compiler/rules/pattern.h index d2081962..00560125 100644 --- a/src/compiler/rules/pattern.h +++ b/src/compiler/rules/pattern.h @@ -14,7 +14,7 @@ namespace tree_sitter { size_t hash_code() const; rule_ptr copy() const; std::string to_string() const; - void accept(Visitor &visitor) const; + void accept(Visitor *visitor) const; rule_ptr to_rule_tree() const; }; diff --git a/src/compiler/rules/repeat.cc b/src/compiler/rules/repeat.cc index 3e6ade50..a0e4445b 100644 --- a/src/compiler/rules/repeat.cc +++ b/src/compiler/rules/repeat.cc @@ -24,8 +24,8 @@ namespace tree_sitter { return string("#to_string() + ">"; } - void Repeat::accept(Visitor &visitor) const { - visitor.visit(this); + void Repeat::accept(Visitor *visitor) const { + visitor->visit(this); } } } diff --git a/src/compiler/rules/repeat.h b/src/compiler/rules/repeat.h index 013dea96..52673662 100644 --- a/src/compiler/rules/repeat.h +++ b/src/compiler/rules/repeat.h @@ -13,7 +13,7 @@ namespace tree_sitter { size_t hash_code() const; rule_ptr copy() const; std::string to_string() const; - void accept(Visitor &visitor) const; + void accept(Visitor *visitor) const; const rule_ptr content; }; diff --git a/src/compiler/rules/rule.h b/src/compiler/rules/rule.h index 48141de5..5cc64203 100644 --- a/src/compiler/rules/rule.h +++ b/src/compiler/rules/rule.h @@ -18,7 +18,7 @@ namespace tree_sitter { virtual size_t hash_code() const = 0; virtual rule_ptr copy() const = 0; virtual std::string to_string() const = 0; - virtual void accept(Visitor &visitor) const = 0; + virtual void accept(Visitor *visitor) const = 0; }; std::ostream& operator<<(std::ostream& stream, const Rule &rule); diff --git a/src/compiler/rules/seq.cc b/src/compiler/rules/seq.cc index fb52f420..bd0d0690 100644 --- a/src/compiler/rules/seq.cc +++ b/src/compiler/rules/seq.cc @@ -34,8 +34,8 @@ namespace tree_sitter { return string("#to_string() + " " + right->to_string() + ">"; } - void Seq::accept(Visitor &visitor) const { - visitor.visit(this); + void Seq::accept(Visitor *visitor) const { + visitor->visit(this); } } } diff --git a/src/compiler/rules/seq.h b/src/compiler/rules/seq.h index 5f00d6f9..6a92044c 100644 --- a/src/compiler/rules/seq.h +++ b/src/compiler/rules/seq.h @@ -15,7 +15,7 @@ namespace tree_sitter { size_t hash_code() const; rule_ptr copy() const; std::string to_string() const; - void accept(Visitor &visitor) const; + void accept(Visitor *visitor) const; const rule_ptr left; const rule_ptr right; diff --git a/src/compiler/rules/string.cc b/src/compiler/rules/string.cc index 4e6ffd4d..509ef253 100644 --- a/src/compiler/rules/string.cc +++ b/src/compiler/rules/string.cc @@ -25,8 +25,8 @@ namespace tree_sitter { return string("#"; } - void String::accept(Visitor &visitor) const { - visitor.visit(this); + void String::accept(Visitor *visitor) const { + visitor->visit(this); } } } diff --git a/src/compiler/rules/string.h b/src/compiler/rules/string.h index 0bc28c94..5cf3cd4a 100644 --- a/src/compiler/rules/string.h +++ b/src/compiler/rules/string.h @@ -13,7 +13,7 @@ namespace tree_sitter { size_t hash_code() const; rule_ptr copy() const; std::string to_string() const; - void accept(Visitor &visitor) const; + void accept(Visitor *visitor) const; const std::string value; }; diff --git a/src/compiler/rules/symbol.cc b/src/compiler/rules/symbol.cc index cc5750f9..2e50c45f 100644 --- a/src/compiler/rules/symbol.cc +++ b/src/compiler/rules/symbol.cc @@ -58,8 +58,8 @@ namespace tree_sitter { return (type == SymbolTypeHidden || type == SymbolTypeAuxiliary); } - void Symbol::accept(Visitor &visitor) const { - visitor.visit(this); + void Symbol::accept(Visitor *visitor) const { + visitor->visit(this); } } } \ No newline at end of file diff --git a/src/compiler/rules/symbol.h b/src/compiler/rules/symbol.h index d1b4e912..4d76d756 100644 --- a/src/compiler/rules/symbol.h +++ b/src/compiler/rules/symbol.h @@ -24,7 +24,7 @@ namespace tree_sitter { size_t hash_code() const; rule_ptr copy() const; std::string to_string() const; - void accept(Visitor &visitor) const; + void accept(Visitor *visitor) const; bool operator<(const Symbol &other) const; bool is_built_in() const; diff --git a/src/compiler/rules/visitor.h b/src/compiler/rules/visitor.h index 6cf075aa..3973ad9c 100644 --- a/src/compiler/rules/visitor.h +++ b/src/compiler/rules/visitor.h @@ -34,7 +34,7 @@ namespace tree_sitter { public: T apply(const rule_ptr &rule) { value = T(); - rule->accept(*this); + rule->accept(this); return value; } };