Skip to content

Commit

Permalink
fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
ckrause committed Jun 14, 2024
1 parent 1736a61 commit 276e942
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/form/expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions src/form/expression_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/form/formula.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ std::multimap<std::string, std::string> 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) {
Expand Down Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion src/form/formula.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Formula {
std::multimap<std::string, std::string> 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);

Expand Down
8 changes: 4 additions & 4 deletions src/form/formula_gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,15 @@ 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
}
}
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();
Expand Down Expand Up @@ -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;
}
Expand All @@ -419,7 +419,7 @@ void FormulaGenerator::simplifyFunctionNames() {
bool addProgramIds(const Program& p, std::set<int64_t>& 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()) {
Expand Down
2 changes: 1 addition & 1 deletion src/form/pari.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/form/variant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ VariantsManager::VariantsManager(
const Formula& formula,
const std::map<std::string, int64_t>& 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;
Expand Down Expand Up @@ -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);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/lang/analyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/lang/comments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down
8 changes: 4 additions & 4 deletions src/lang/evaluator_inc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -191,7 +191,7 @@ void IncrementalEvaluator::computeStatefulCells() {
std::set<int64_t> read;
std::set<int64_t> 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;
Expand Down Expand Up @@ -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) !=
Expand Down Expand Up @@ -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<int64_t> 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;
Expand Down

0 comments on commit 276e942

Please sign in to comment.