diff --git a/src/form/expression.cpp b/src/form/expression.cpp index b6c944fc..683cda6e 100644 --- a/src/form/expression.cpp +++ b/src/form/expression.cpp @@ -128,7 +128,7 @@ bool Expression::contains(Type t, const std::string& name) const { size_t Expression::numTerms() const { size_t result = 1; - for (auto& c : children) { + for (const auto& c : children) { result += c.numTerms(); } return result; diff --git a/src/form/expression_util.cpp b/src/form/expression_util.cpp index b86eb196..4cb6e235 100644 --- a/src/form/expression_util.cpp +++ b/src/form/expression_util.cpp @@ -124,9 +124,9 @@ bool pullUpChildren(Expression& e) { } Expression result(e.type, e.name, e.value); bool changed = false; - for (auto& c : e.children) { + for (const auto& c : e.children) { if (c.type == e.type) { - for (auto& d : c.children) { + for (const auto& d : c.children) { result.newChild(d); } changed = true; @@ -157,10 +157,10 @@ bool multiplyThrough(Expression& e) { auto sum = e.children[1]; // copy e.type = Expression::Type::SUM; e.children.clear(); - for (auto& c : sum.children) { + for (const auto& c : sum.children) { Expression prod(Expression::Type::PRODUCT, "", {constant}); if (c.type == Expression::Type::PRODUCT) { - for (auto d : c.children) { + for (const auto& d : c.children) { prod.newChild(d); } } else { @@ -326,7 +326,7 @@ void ExpressionUtil::collectNames(const Expression& e, Expression::Type type, if (e.type == type) { target.insert(e.name); } - for (auto& c : e.children) { + for (const auto& c : e.children) { collectNames(c, type, target); } } @@ -348,14 +348,14 @@ Number ExpressionUtil::eval(const Expression& e, } case Expression::Type::SUM: { auto result = Number::ZERO; - for (auto c : e.children) { + for (const auto& c : e.children) { result = Semantics::add(result, eval(c, params)); } return result; } case Expression::Type::PRODUCT: { auto result = Number::ONE; - for (auto c : e.children) { + for (const auto& c : e.children) { result = Semantics::mul(result, eval(c, params)); } return result; diff --git a/src/form/formula.cpp b/src/form/formula.cpp index bde0a038..24bb9d55 100644 --- a/src/form/formula.cpp +++ b/src/form/formula.cpp @@ -108,7 +108,7 @@ std::multimap Formula::getFunctionDeps( return deps; } -bool Formula::isRecursive(std::string funcName) const { +bool Formula::isRecursive(const std::string& funcName) const { auto deps = getFunctionDeps(false, false); for (auto it : deps) { if (it.first == funcName && it.second == funcName) { @@ -158,7 +158,7 @@ void Formula::collectEntries(const Expression& e, Formula& target) { if (e.type == Expression::Type::FUNCTION && !e.name.empty()) { collectEntries(e.name, target); } - for (auto& c : e.children) { + for (const auto& c : e.children) { collectEntries(c, target); } } diff --git a/src/form/formula.hpp b/src/form/formula.hpp index 416d28f7..634b2262 100644 --- a/src/form/formula.hpp +++ b/src/form/formula.hpp @@ -28,7 +28,7 @@ class Formula { std::multimap getFunctionDeps( bool transitive, bool ignoreSelf) const; - bool isRecursive(std::string funcName) const; + bool isRecursive(const std::string& funcName) const; void replaceAll(const Expression& from, const Expression& to); diff --git a/src/form/formula_gen.cpp b/src/form/formula_gen.cpp index ec314d42..aa88c28d 100644 --- a/src/form/formula_gen.cpp +++ b/src/form/formula_gen.cpp @@ -177,7 +177,7 @@ bool FormulaGenerator::update(const Operation& op) { } bool FormulaGenerator::update(const Program& p) { - for (auto& op : p.ops) { + for (const auto& op : p.ops) { if (!update(op)) { return false; // operation not supported } @@ -185,7 +185,7 @@ bool FormulaGenerator::update(const Program& p) { return true; } -int64_t getNumInitialTermsNeeded(int64_t cell, const std::string fname, +int64_t getNumInitialTermsNeeded(int64_t cell, const std::string& fname, const Formula& formula, const IncrementalEvaluator& ie) { auto stateful = ie.getStatefulCells(); @@ -406,7 +406,7 @@ void FormulaGenerator::simplifyFunctionNames() { } formula.replaceName(getCellName(0), canonicalName(0)); size_t cell = 1; - for (auto& n : names) { + for (const auto& n : names) { if (n == getCellName(0)) { continue; } @@ -419,7 +419,7 @@ void FormulaGenerator::simplifyFunctionNames() { bool addProgramIds(const Program& p, std::set& ids) { // TODO: check for recursion Parser parser; - for (auto op : p.ops) { + for (const auto& op : p.ops) { if (op.type == Operation::Type::SEQ) { auto id = op.source.value.asInt(); if (ids.find(id) == ids.end()) { diff --git a/src/form/pari.cpp b/src/form/pari.cpp index 5431121f..b1c81ce6 100644 --- a/src/form/pari.cpp +++ b/src/form/pari.cpp @@ -55,7 +55,7 @@ void countFuncs(const Formula& f, const Expression& e, count[e]++; } } - for (auto& c : e.children) { + for (const auto& c : e.children) { countFuncs(f, c, count); } } diff --git a/src/form/variant.cpp b/src/form/variant.cpp index 64a4be9b..5103744a 100644 --- a/src/form/variant.cpp +++ b/src/form/variant.cpp @@ -7,13 +7,13 @@ VariantsManager::VariantsManager( const Formula& formula, const std::map& num_initial_terms) { // step 1: collect function names - for (auto& entry : formula.entries) { + for (const auto& entry : formula.entries) { if (ExpressionUtil::isSimpleFunction(entry.first, true)) { variants[entry.first.name] = {}; } } // step 2: initialize function variants - for (auto& entry : formula.entries) { + for (const auto& entry : formula.entries) { if (ExpressionUtil::isSimpleFunction(entry.first, true)) { Variant variant; variant.func = entry.first.name; @@ -81,7 +81,7 @@ void VariantsManager::collectFuncs(Variant& variant, variant.required_funcs.insert(expr.name); } } - for (auto& c : expr.children) { + for (const auto& c : expr.children) { collectFuncs(variant, c); } } diff --git a/src/lang/analyzer.cpp b/src/lang/analyzer.cpp index 31d51794..6dc6dec1 100644 --- a/src/lang/analyzer.cpp +++ b/src/lang/analyzer.cpp @@ -66,7 +66,7 @@ bool Analyzer::hasLogarithmicComplexity(const Program& program) { } // check updates of loop counter cell in loop body bool loop_counter_updated = false; - for (auto& op : simple_loop.body.ops) { + for (const auto& op : simple_loop.body.ops) { const auto target = op.target.value.asInt(); if (target == simple_loop.counter) { // loop counter must be updated using division @@ -104,7 +104,7 @@ bool isExponentialPreLoop(const Program& pre_loop, int64_t counter) { return false; } int64_t phase = 0; - for (auto& op : pre_loop.ops) { + for (const auto& op : pre_loop.ops) { auto target = op.target.value.asInt(); // loop counter update if (target == counter) { diff --git a/src/lang/comments.cpp b/src/lang/comments.cpp index 417f5aca..782c87fe 100644 --- a/src/lang/comments.cpp +++ b/src/lang/comments.cpp @@ -54,7 +54,7 @@ std::string Comments::getSequenceIdFromProgram(const Program &p) { if (p.ops.empty()) { return id_str; // not found } - auto &c = p.ops[0].comment; + const auto &c = p.ops[0].comment; if (c.length() > 1 && c[0] == 'A' && std::isdigit(c[1])) { id_str = c.substr(0, 2); for (size_t i = 2; i < c.length() && std::isdigit(c[i]); i++) { diff --git a/src/lang/evaluator_inc.cpp b/src/lang/evaluator_inc.cpp index 1118d1fd..a21aade1 100644 --- a/src/lang/evaluator_inc.cpp +++ b/src/lang/evaluator_inc.cpp @@ -126,7 +126,7 @@ bool IncrementalEvaluator::checkPreLoop(bool skip_input_transform) { bool IncrementalEvaluator::checkLoopBody() { // check loop counter cell bool loop_counter_updated = false; - for (auto& op : simple_loop.body.ops) { + for (const auto& op : simple_loop.body.ops) { const auto meta = Operation::Metadata::get(op.type); const auto target = op.target.value.asInt(); if (target == simple_loop.counter) { @@ -191,7 +191,7 @@ void IncrementalEvaluator::computeStatefulCells() { std::set read; std::set write; stateful_cells.clear(); - for (auto& op : simple_loop.body.ops) { + for (const auto& op : simple_loop.body.ops) { const auto meta = Operation::Metadata::get(op.type); if (meta.num_operands == 0) { continue; @@ -222,7 +222,7 @@ void IncrementalEvaluator::computeLoopCounterDependentCells() { bool changed = true; while (changed) { changed = false; - for (auto& op : simple_loop.body.ops) { + for (const auto& op : simple_loop.body.ops) { const auto meta = Operation::Metadata::get(op.type); const auto target = op.target.value.asInt(); if (loop_counter_dependent_cells.find(target) != @@ -253,7 +253,7 @@ bool IncrementalEvaluator::checkPostLoop() { // initialize output cells. all memory cells that are read // by the post-loop fragment are output cells. std::set write; - for (auto& op : simple_loop.post_loop.ops) { + for (const auto& op : simple_loop.post_loop.ops) { const auto meta = Operation::Metadata::get(op.type); if (meta.num_operands < 1) { continue;