Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some clang tidy warnings #2464

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ast/Constraint.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Constraint : public Literal {
public:
using Literal::Literal;

Constraint(NodeKind kind, SrcLocation loc = {}) : Literal(kind, loc) {
Constraint(NodeKind kind, SrcLocation loc = {}) : Literal(kind, std::move(loc)) {
assert(kind >= NK_Constraint && kind < NK_LastConstraint);
}

Expand Down
2 changes: 1 addition & 1 deletion src/ast/Functor.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Functor : public Term {
protected:
using Term::Term;

Functor(NodeKind kind, SrcLocation loc = {}) : Term(kind, loc) {
Functor(NodeKind kind, SrcLocation loc = {}) : Term(kind, std::move(loc)) {
assert(kind > NK_FirstFunctor && kind < NK_LastFunctor);
}

Expand Down
2 changes: 1 addition & 1 deletion src/ast/Lattice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void Lattice::setQualifiedName(QualifiedName name) {
this->name = std::move(name);
}

const std::map<LatticeOperator, const ast::Argument*> Lattice::getOperators() const {
std::map<LatticeOperator, const ast::Argument*> Lattice::getOperators() const {
std::map<LatticeOperator, const ast::Argument*> ops;
for (const auto& [op, arg] : operators) {
ops.emplace(std::make_pair(op, arg.get()));
Expand Down
2 changes: 1 addition & 1 deletion src/ast/Lattice.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Lattice : public Node {
/** Set type name */
void setQualifiedName(QualifiedName name);

const std::map<LatticeOperator, const ast::Argument*> getOperators() const;
std::map<LatticeOperator, const ast::Argument*> getOperators() const;

bool hasGlb() const;
bool hasLub() const;
Expand Down
2 changes: 1 addition & 1 deletion src/ast/Literal.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Literal : public Node {
public:
using Node::Node;

explicit Literal(NodeKind kind, SrcLocation loc = {}) : Node(kind, loc) {
explicit Literal(NodeKind kind, SrcLocation loc = {}) : Node(kind, std::move(loc)) {
assert(kind >= NK_Literal && kind < NK_LastLiteral);
}

Expand Down
2 changes: 1 addition & 1 deletion src/ast/UnnamedVariable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace souffle::ast {

UnnamedVariable::UnnamedVariable(SrcLocation loc) : Argument(NK_UnnamedVariable, loc) {}
UnnamedVariable::UnnamedVariable(SrcLocation loc) : Argument(NK_UnnamedVariable, std::move(loc)) {}

void UnnamedVariable::print(std::ostream& os) const {
os << "_";
Expand Down
4 changes: 2 additions & 2 deletions src/ast/UserDefinedAggregator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
namespace souffle::ast {
UserDefinedAggregator::UserDefinedAggregator(
std::string name, Own<Argument> init, Own<Argument> expr, VecOwn<Literal> body, SrcLocation loc)
: Aggregator(NK_UserDefinedAggregator, std::move(expr), std::move(body), std::move(loc)), name(name),
initValue(std::move(init)) {}
: Aggregator(NK_UserDefinedAggregator, std::move(expr), std::move(body), std::move(loc)),
name(std::move(name)), initValue(std::move(init)) {}

void UserDefinedAggregator::apply(const NodeMapper& map) {
Aggregator::apply(map);
Expand Down
8 changes: 4 additions & 4 deletions src/ast/analysis/Aggregate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ std::set<std::string> getWitnessVariables(
M update;
aggregatorlessClause->apply(update);
auto groundingAtom = mk<Atom>(QualifiedName::fromString("+grounding_atom"));
for (std::string variableName : update.getAggregatorVariables()) {
for (const std::string& variableName : update.getAggregatorVariables()) {
groundingAtom->addArgument(mk<Variable>(variableName));
}
aggregatorlessClause->addToBody(std::move(groundingAtom));
Expand Down Expand Up @@ -163,7 +163,7 @@ std::set<std::string> getVariablesOutsideAggregate(const Clause& clause, const A
return variablesOutsideAggregate;
}

std::string findUniqueVariableName(const Clause& clause, std::string base) {
std::string findUniqueVariableName(const Clause& clause, const std::string& base) {
std::set<std::string> variablesInClause;
visit(clause, [&](const Variable& v) { variablesInClause.insert(v.getName()); });
int varNum = 0;
Expand All @@ -174,7 +174,7 @@ std::string findUniqueVariableName(const Clause& clause, std::string base) {
return candidate;
}

std::string findUniqueRelationName(const Program& program, std::string base) {
std::string findUniqueRelationName(const Program& program, const std::string& base) {
int counter = 0;
auto candidate = base;
while (program.getRelation(QualifiedName::fromString(candidate)) != nullptr) {
Expand Down Expand Up @@ -331,7 +331,7 @@ std::set<std::string> getInjectedVariables(
tweakedClause->apply(update);
// the update will now tell us which variables we need to ground!
auto groundingAtom = mk<Atom>(QualifiedName::fromString("+grounding_atom"));
for (std::string variableName : update.getAggregatorVariables()) {
for (const std::string& variableName : update.getAggregatorVariables()) {
groundingAtom->addArgument(mk<Variable>(variableName));
}
// add the newly created grounding atom to the body
Expand Down
4 changes: 2 additions & 2 deletions src/ast/analysis/Aggregate.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ std::set<std::string> getVariablesOutsideAggregate(const Clause& clause, const A
* Find a new relation name. I use this when I create new relations either for
* aggregate bodies or singleton aggregates.
**/
std::string findUniqueRelationName(const Program& program, std::string base);
std::string findUniqueRelationName(const Program& program, const std::string& base);
/**
* Find a variable name using base to form a string like base1
* Use this when you need to limit the scope of a variable to the inside of an aggregate.
**/
std::string findUniqueVariableName(const Clause& clause, std::string base);
std::string findUniqueVariableName(const Clause& clause, const std::string& base);
/**
* Given an aggregate and a clause, we find all the variables that have been
* injected into the aggregate.
Expand Down
4 changes: 2 additions & 2 deletions src/ast/analysis/IOType.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ class IOTypeAnalysis : public Analysis {
auto iter = limitSize.find(relation);
if (iter != limitSize.end()) {
return (*iter).second;
} else
return 0;
}
return 0;
}

bool isIO(const Relation* relation) const {
Expand Down
4 changes: 2 additions & 2 deletions src/ast/analysis/typesystem/TypeSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,8 @@ struct RecordType : public Type {

protected:
RecordType(const TypeEnvironment& environment, const QualifiedName& name,
const std::vector<const Type*> fields = {})
: Type(TK_RecordType, environment, name), fields(fields) {}
std::vector<const Type*> fields = {})
: Type(TK_RecordType, environment, name), fields(std::move(fields)) {}

private:
friend class TypeEnvironment;
Expand Down
2 changes: 1 addition & 1 deletion src/ast2ram/utility/ValueIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void ValueIndex::addVarReference(std::string varName, const Location& l) {
}

void ValueIndex::addVarReference(std::string varName, std::size_t ident, std::size_t pos) {
addVarReference(varName, Location({ident, pos}));
addVarReference(std::move(varName), Location({ident, pos}));
}

bool ValueIndex::isDefined(const std::string& varName) const {
Expand Down
2 changes: 1 addition & 1 deletion src/include/souffle/RecordTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace souffle {
/** The interface of any Record Table. */
class RecordTable {
public:
virtual ~RecordTable() {}
virtual ~RecordTable() = default;

virtual void setNumLanes(const std::size_t NumLanes) = 0;

Expand Down
10 changes: 4 additions & 6 deletions src/include/souffle/SouffleInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class Relation {
/**
* Move constructor.
*
* The new iterator now has ownerhsip of the iterator base.
* The new iterator now has ownership of the iterator base.
*
* @param arg lvalue reference to an iterator object
*/
Expand Down Expand Up @@ -215,7 +215,7 @@ class Relation {
return *this;
}

iterator& operator=(iterator&& o) {
iterator& operator=(iterator&& o) noexcept {
iter.swap(o.iter);
return *this;
}
Expand Down Expand Up @@ -845,9 +845,8 @@ class SouffleProgram {
auto it = relationMap.find(name);
if (it != relationMap.end()) {
return (*it).second;
} else {
return nullptr;
}
return nullptr;
};

/**
Expand Down Expand Up @@ -1137,9 +1136,8 @@ class ProgramFactory {
ProgramFactory* factory = find(name);
if (factory != nullptr) {
return factory->newInstance();
} else {
return nullptr;
}
return nullptr;
}
};
} // namespace souffle
6 changes: 3 additions & 3 deletions src/include/souffle/SymbolTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace souffle {
/** Interface of a generic SymbolTable iterator. */
class SymbolTableIteratorInterface {
public:
virtual ~SymbolTableIteratorInterface() {}
virtual ~SymbolTableIteratorInterface() = default;

virtual const std::pair<const std::string, const std::size_t>& get() const = 0;

Expand All @@ -44,7 +44,7 @@ class SymbolTableIteratorInterface {
*/
class SymbolTable {
public:
virtual ~SymbolTable() {}
virtual ~SymbolTable() = default;

/**
* @brief Iterator on a symbol table.
Expand All @@ -61,7 +61,7 @@ class SymbolTable {

Iterator(const Iterator& it) : impl(it.impl->copy()) {}

Iterator(Iterator&& it) : impl(std::move(it.impl)) {}
Iterator(Iterator&& it) noexcept : impl(std::move(it.impl)) {}

reference operator*() const {
return impl->get();
Expand Down
26 changes: 13 additions & 13 deletions src/include/souffle/datastructure/BTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ class btree {
}

// copy child nodes recursively
auto* ires = (inner_node*)res;
auto* ires = static_cast<inner_node*>(res);
for (size_type i = 0; i <= this->numElements; ++i) {
ires->children[i] = this->getChild(i)->clone();
ires->children[i]->parent = res;
Expand Down Expand Up @@ -634,7 +634,7 @@ class btree {
}

// move bigger keys one forward
for (int i = static_cast<int>(this->numElements) - 1; i >= (int)pos; --i) {
for (int i = static_cast<int>(this->numElements) - 1; i >= static_cast<int>(pos); --i) {
keys[i + 1] = keys[i];
getChildren()[i + 2] = getChildren()[i + 1];
++getChildren()[i + 2]->position;
Expand All @@ -660,7 +660,7 @@ class btree {
*/
void printTree(std::ostream& out, const std::string& prefix) const {
// print the header
out << prefix << "@" << this << "[" << ((int)(this->position)) << "] - "
out << prefix << "@" << this << "[" << static_cast<int>(this->position) << "] - "
<< (this->inner ? "i" : "") << "node : " << this->numElements << "/" << maxKeys << " [";

// print the keys
Expand Down Expand Up @@ -806,7 +806,7 @@ class btree {
std::cout << "Parent reference invalid!\n";
std::cout << " Node: " << this << "\n";
std::cout << " Parent: " << this->parent << "\n";
std::cout << " Position: " << ((int)this->position) << "\n";
std::cout << " Position: " << static_cast<int>(this->position) << "\n";
valid = false;
}

Expand All @@ -816,7 +816,7 @@ class btree {
std::cout << "Left parent key not lower bound!\n";
std::cout << " Node: " << this << "\n";
std::cout << " Parent: " << this->parent << "\n";
std::cout << " Position: " << ((int)this->position) << "\n";
std::cout << " Position: " << static_cast<int>(this->position) << "\n";
std::cout << " Key: " << (this->parent->keys[this->position]) << "\n";
std::cout << " Lower: " << (keys[0]) << "\n";
valid = false;
Expand All @@ -829,7 +829,7 @@ class btree {
std::cout << "Right parent key not lower bound!\n";
std::cout << " Node: " << this << "\n";
std::cout << " Parent: " << this->parent << "\n";
std::cout << " Position: " << ((int)this->position) << "\n";
std::cout << " Position: " << static_cast<int>(this->position) << "\n";
std::cout << " Key: " << (this->parent->keys[this->position]) << "\n";
std::cout << " Upper: " << (keys[0]) << "\n";
valid = false;
Expand Down Expand Up @@ -982,7 +982,7 @@ class btree {

// prints a textual representation of this iterator to the given stream (mainly for debugging)
void print(std::ostream& out = std::cout) const {
out << cur << "[" << (int)pos << "]";
out << cur << "[" << static_cast<int>(pos) << "]";
}
};

Expand Down Expand Up @@ -1075,7 +1075,7 @@ class btree {
}

// a move constructor
btree(btree&& other)
btree(btree&& other) noexcept
: comp(other.comp), weak_comp(other.weak_comp), root(other.root), leftmost(other.leftmost) {
other.root = nullptr;
other.leftmost = nullptr;
Expand Down Expand Up @@ -1360,7 +1360,7 @@ class btree {
}

// insert element in right fragment
if (((size_type)idx) > cur->numElements) {
if (static_cast<size_type>(idx) > cur->numElements) {
// release current lock
cur->lock.end_write();

Expand Down Expand Up @@ -1858,8 +1858,8 @@ class btree {
out << " Size of leaf node: " << sizeof(leaf_node) << "\n";
out << " Size of Key: " << sizeof(Key) << "\n";
out << " max keys / node: " << node::maxKeys << "\n";
out << " avg keys / node: " << (size() / (double)nodes) << "\n";
out << " avg filling rate: " << ((size() / (double)nodes) / node::maxKeys) << "\n";
out << " avg keys / node: " << (size() / static_cast<double>(nodes)) << "\n";
out << " avg filling rate: " << ((size() / static_cast<double>(nodes)) / node::maxKeys) << "\n";
out << " ---------------------------------\n";
out << " insert-hint (hits/misses/total): " << hint_stats.inserts.getHits() << "/"
<< hint_stats.inserts.getMisses() << "/" << hint_stats.inserts.getAccesses() << "\n";
Expand Down Expand Up @@ -2061,7 +2061,7 @@ class btree_set : public souffle::detail::btree<Key, Comparator, Allocator, bloc
btree_set(const btree_set& other) : super(other) {}

// A move constructor.
btree_set(btree_set&& other) : super(std::move(other)) {}
btree_set(btree_set&& other) noexcept : super(std::move(other)) {}

private:
// A constructor required by the bulk-load facility.
Expand Down Expand Up @@ -2123,7 +2123,7 @@ class btree_multiset : public souffle::detail::btree<Key, Comparator, Allocator,
btree_multiset(const btree_multiset& other) : super(other) {}

// A move constructor.
btree_multiset(btree_multiset&& other) : super(std::move(other)) {}
btree_multiset(btree_multiset&& other) noexcept : super(std::move(other)) {}

private:
// A constructor required by the bulk-load facility.
Expand Down
Loading