refactor: fix clang-tidy auto*, const&, and curly braces (#5083)

This commit is contained in:
pajlada
2024-01-14 17:54:52 +01:00
committed by GitHub
parent 292f9b9734
commit 5b6675abb4
78 changed files with 647 additions and 228 deletions
+6
View File
@@ -19,7 +19,9 @@ FilterSet::FilterSet(const QList<QUuid> &filterIds)
for (const auto &f : *filters)
{
if (filterIds.contains(f->getId()))
{
this->filters_.insert(f->getId(), f);
}
}
this->listener_ =
@@ -36,13 +38,17 @@ FilterSet::~FilterSet()
bool FilterSet::filter(const MessagePtr &m, ChannelPtr channel) const
{
if (this->filters_.size() == 0)
{
return true;
}
filters::ContextMap context = filters::buildContextMap(m, channel.get());
for (const auto &f : this->filters_.values())
{
if (!f->valid() || !f->filter(context))
{
return false;
}
}
return true;
@@ -105,7 +105,9 @@ QString Tokenizer::current() const
QString Tokenizer::preview() const
{
if (this->hasNext())
{
return this->tokens_.at(this->i_);
}
return "";
}
@@ -172,51 +174,97 @@ const QStringList Tokenizer::allTokens()
TokenType Tokenizer::tokenize(const QString &text)
{
if (text == "&&")
{
return TokenType::AND;
}
else if (text == "||")
{
return TokenType::OR;
}
else if (text == "(")
{
return TokenType::LP;
}
else if (text == ")")
{
return TokenType::RP;
}
else if (text == "{")
{
return TokenType::LIST_START;
}
else if (text == "}")
{
return TokenType::LIST_END;
}
else if (text == ",")
{
return TokenType::COMMA;
}
else if (text == "+")
{
return TokenType::PLUS;
}
else if (text == "-")
{
return TokenType::MINUS;
}
else if (text == "*")
{
return TokenType::MULTIPLY;
}
else if (text == "/")
{
return TokenType::DIVIDE;
}
else if (text == "==")
{
return TokenType::EQ;
}
else if (text == "!=")
{
return TokenType::NEQ;
}
else if (text == "%")
{
return TokenType::MOD;
}
else if (text == "<")
{
return TokenType::LT;
}
else if (text == ">")
{
return TokenType::GT;
}
else if (text == "<=")
{
return TokenType::LTE;
}
else if (text == ">=")
{
return TokenType::GTE;
}
else if (text == "contains")
{
return TokenType::CONTAINS;
}
else if (text == "startswith")
{
return TokenType::STARTS_WITH;
}
else if (text == "endswith")
{
return TokenType::ENDS_WITH;
}
else if (text == "match")
{
return TokenType::MATCH;
}
else if (text == "!")
{
return TokenType::NOT;
}
else
{
if ((text.startsWith("r\"") || text.startsWith("ri\"")) &&
@@ -226,14 +274,20 @@ TokenType Tokenizer::tokenize(const QString &text)
}
if (text.front() == '"' && text.back() == '"')
{
return TokenType::STRING;
}
if (validIdentifiersMap.keys().contains(text))
{
return TokenType::IDENTIFIER;
}
bool flag;
if (text.toInt(&flag); flag)
{
return TokenType::INT;
}
}
return TokenType::NONE;
@@ -69,27 +69,39 @@ QVariant BinaryOperation::execute(const ContextMap &context) const
return 0;
case MINUS:
if (convertVariantTypes(left, right, QMetaType::Int))
{
return left.toInt() - right.toInt();
}
return 0;
case MULTIPLY:
if (convertVariantTypes(left, right, QMetaType::Int))
{
return left.toInt() * right.toInt();
}
return 0;
case DIVIDE:
if (convertVariantTypes(left, right, QMetaType::Int))
{
return left.toInt() / right.toInt();
}
return 0;
case MOD:
if (convertVariantTypes(left, right, QMetaType::Int))
{
return left.toInt() % right.toInt();
}
return 0;
case OR:
if (convertVariantTypes(left, right, QMetaType::Bool))
{
return left.toBool() || right.toBool();
}
return false;
case AND:
if (convertVariantTypes(left, right, QMetaType::Bool))
{
return left.toBool() && right.toBool();
}
return false;
case EQ:
if (variantTypesMatch(left, right, QMetaType::QString))
@@ -107,19 +119,27 @@ QVariant BinaryOperation::execute(const ContextMap &context) const
return !looselyCompareVariants(left, right);
case LT:
if (convertVariantTypes(left, right, QMetaType::Int))
{
return left.toInt() < right.toInt();
}
return false;
case GT:
if (convertVariantTypes(left, right, QMetaType::Int))
{
return left.toInt() > right.toInt();
}
return false;
case LTE:
if (convertVariantTypes(left, right, QMetaType::Int))
{
return left.toInt() <= right.toInt();
}
return false;
case GTE:
if (convertVariantTypes(left, right, QMetaType::Int))
{
return left.toInt() >= right.toInt();
}
return false;
case CONTAINS:
if (variantIs(left, QMetaType::QStringList) &&
@@ -215,22 +235,30 @@ QVariant BinaryOperation::execute(const ContextMap &context) const
// list must be two items
if (list.size() != 2)
{
return false;
}
// list must be a regular expression and an int
if (variantIsNot(list.at(0),
QMetaType::QRegularExpression) ||
variantIsNot(list.at(1), QMetaType::Int))
{
return false;
}
auto match =
list.at(0).toRegularExpression().match(matching);
// if matched, return nth capture group. Otherwise, return ""
if (match.hasMatch())
{
return match.captured(list.at(1).toInt());
}
else
{
return "";
}
}
default:
return false;
@@ -263,9 +291,13 @@ PossibleType BinaryOperation::synthesizeType(const TypingContext &context) const
{
case PLUS:
if (left == Type::String)
{
return TypeClass{Type::String}; // String concatenation
}
else if (left == Type::Int && right == Type::Int)
{
return TypeClass{Type::Int};
}
return IllTyped{this, "Can only add Ints or concatenate a String"};
case MINUS:
@@ -273,13 +305,17 @@ PossibleType BinaryOperation::synthesizeType(const TypingContext &context) const
case DIVIDE:
case MOD:
if (left == Type::Int && right == Type::Int)
{
return TypeClass{Type::Int};
}
return IllTyped{this, "Can only perform operation with Ints"};
case OR:
case AND:
if (left == Type::Bool && right == Type::Bool)
{
return TypeClass{Type::Bool};
}
return IllTyped{this,
"Can only perform logical operations with Bools"};
@@ -292,37 +328,53 @@ PossibleType BinaryOperation::synthesizeType(const TypingContext &context) const
case LTE:
case GTE:
if (left == Type::Int && right == Type::Int)
{
return TypeClass{Type::Bool};
}
return IllTyped{this, "Can only perform comparisons with Ints"};
case STARTS_WITH:
case ENDS_WITH:
if (isList(left))
{
return TypeClass{Type::Bool};
}
if (left == Type::String && right == Type::String)
{
return TypeClass{Type::Bool};
}
return IllTyped{
this,
"Can only perform starts/ends with a List or two Strings"};
case CONTAINS:
if (isList(left) || left == Type::Map)
{
return TypeClass{Type::Bool};
}
if (left == Type::String && right == Type::String)
{
return TypeClass{Type::Bool};
}
return IllTyped{
this,
"Can only perform contains with a List, a Map, or two Strings"};
case MATCH: {
if (left != Type::String)
{
return IllTyped{this,
"Left argument of match must be a String"};
}
if (right == Type::RegularExpression)
{
return TypeClass{Type::Bool};
if (right == Type::MatchingSpecifier) // group capturing
}
if (right == Type::MatchingSpecifier)
{ // group capturing
return TypeClass{Type::String};
}
return IllTyped{this, "Can only match on a RegularExpression or a "
"MatchingSpecifier"};