Skip to content

Commit

Permalink
More clang-tidy cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
dburkart committed Dec 20, 2023
1 parent ad8838e commit d204ce4
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 80 deletions.
2 changes: 1 addition & 1 deletion src/AST/ASTString.hh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public:

void accept(ASTVisitor &visitor);

std::string value() const { return this->_str; }
std::string_view value() const { return std::string_view{ this->_str }; }

template<class T>
std::vector<ASTNode *>::const_iterator find(const T& value) const {
Expand Down
10 changes: 6 additions & 4 deletions src/AST/ASTTraceVisitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,12 @@ void ASTTraceVisitor::visit( ASTSieve* node ) {
}

void ASTTraceVisitor::visit( ASTString* node ) {
std::string slice = node->value().substr(0, 10);
if (slice != node->value())
slice += "...";
std::cout << "String (\"" << slice << "\")" << std::endl;
const auto slice = node->value().substr(0, 10);
if ( slice != node->value() ) {
std::cout << "String (\"" << slice << "..." << "\")" << std::endl;
} else {
std::cout << "String (\"" << slice << "\")" << std::endl;
}
}

void ASTTraceVisitor::visit( ASTStringList* node ) {
Expand Down
8 changes: 4 additions & 4 deletions src/AST/ASTVerificationVisitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ void ASTVerificationVisitor::visit( ASTRequire* node ) {
children = children[0]->children();
}

for (auto & it : children) {
auto *child = dynamic_cast<ASTString *>(it);
for (const auto & it : children) {
const auto *child = dynamic_cast<ASTString *>(it);
_capability_map[child->value()] = 1;
_enable_capability(child->value());
}
Expand Down Expand Up @@ -215,13 +215,13 @@ void ASTVerificationVisitor::_init() {

}

void ASTVerificationVisitor::_enable_capability(const std::string& capability) {
void ASTVerificationVisitor::_enable_capability(std::string_view capability) {
if (!_options.all_supported_capabilities && !_options.capabilities[capability])
{
_verification_result = {
1,
yy::location(),
"Capability \"" + capability + "\" was requested, but does not seem to be supported by your mail server."
"Capability \"" + std::string{ capability } + "\" was requested, but does not seem to be supported by your mail server."
};
return;
}
Expand Down
10 changes: 5 additions & 5 deletions src/AST/ASTVerificationVisitor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ public:
private:
void _init();
void _traverse_tree(sieve::ASTNode *node);
void _enable_capability(const std::string& capability);
void _enable_capability(std::string_view capability);

struct parse_options _options;
parse_result _verification_result;

std::map<std::string, bool> _capability_map;
std::map<std::string, bool> _command_map;
std::map<std::string, bool> _test_map;
std::map<std::string, bool> _tag_map;
std::map<std::string_view, bool> _capability_map;
std::map<std::string_view, bool> _command_map;
std::map<std::string_view, bool> _test_map;
std::map<std::string_view, bool> _tag_map;

// Validators
Command _command;
Expand Down
52 changes: 25 additions & 27 deletions src/AST/Validation/Command.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ bool Command::validate(const ASTNode *node) {
return true;
}

return (this->*_validation_fn_map[command->value()])(command);
return (this->_validation_fn_map[command->value()])(command);
}

std::string Command::usage(const ASTNode *node) {
Expand All @@ -93,14 +93,14 @@ std::string Command::usage(const ASTNode *node) {
//-- Private members
bool Command::_validateAddHeadersCommand(const ASTNode *node) {
const auto *command = dynamic_cast<const ASTCommand*>(node);
std::vector<sieve::ASTNode *> children = command->children();
size_t size = command->children().size();
const auto children = command->children();
const size_t size = command->children().size();

if (size != 2 && size != 3)
return false;

int i = 0;
for (auto it : children) {
for (const auto it : children) {
const ASTTag *tagChild = dynamic_cast<ASTTag *>(it);
const ASTString *stringChild = dynamic_cast<ASTString *>(it);

Expand All @@ -122,39 +122,37 @@ bool Command::_validateAddHeadersCommand(const ASTNode *node) {

bool Command::_validateDeleteHeadersCommand(const ASTNode *node) {
const auto *command = dynamic_cast<const ASTCommand*>(node);
std::vector<sieve::ASTNode *> children = command->children();
std::vector<ASTNode *>::const_iterator it;
size_t size = command->children().size();
std::vector<ASTNode *> children = command->children();
const size_t size = command->children().size();
size_t minSize = 1;

ASTNumeric* numeric;

// :index
auto indexTag = command->find(ASTTag(":index"));
if (indexTag != command->children().end()) {

// Must be the first child
if (indexTag != command->children().begin())
return false;

minSize += 2;
it = indexTag + 1;
auto it = indexTag + 1;

// Ensure that the next argument is a numeric
//const T* child = dynamic_cast<T*>(*it);
numeric = dynamic_cast<ASTNumeric*>(*it);
const auto numeric = dynamic_cast<ASTNumeric*>(*it);
if (numeric == nullptr)
return false;

indexTag++;
++indexTag;
it = indexTag + 1;

// Allow a :last tag, but only if it's the next child
auto lastTag = command->find(ASTTag(":last"));
const auto lastTag = command->find(ASTTag(":last"));
if (lastTag != command->children().end() && lastTag != it)
return false;

if (lastTag != command->children().end() && lastTag == it) {
indexTag++;
++indexTag;
minSize += 1;
}
} else {
Expand Down Expand Up @@ -187,7 +185,7 @@ bool Command::_validateIncludeCommand(const ASTNode *node) {

bool Command::_validateIMAP4FlagsAction(const ASTNode *node) {
const auto *command = dynamic_cast<const ASTCommand*>(node);
size_t size = command->children().size();
const size_t size = command->children().size();

if (size > 0 && size < 3)
return true;
Expand All @@ -197,7 +195,7 @@ bool Command::_validateIMAP4FlagsAction(const ASTNode *node) {

bool Command::_validateFileintoCommand(const ASTNode *node) {
const auto *command = dynamic_cast<const ASTCommand*>(node);
std::vector<sieve::ASTNode *> children = command->children();
const auto children = command->children();
const size_t size = children.size();

if (size < 1)
Expand All @@ -222,7 +220,7 @@ bool Command::_validateFileintoCommand(const ASTNode *node) {

bool Command::_validateKeepCommand(const ASTNode *node) {
const auto *command = dynamic_cast<const ASTCommand*>(node);
std::vector<sieve::ASTNode *> children = command->children();
const auto children = command->children();
const size_t size = children.size();

size_t numArguments = 0;
Expand All @@ -240,7 +238,7 @@ bool Command::_validateKeepCommand(const ASTNode *node) {

bool Command::_validateReplaceCommand(const ASTNode *node) {
const auto *command = dynamic_cast<const ASTCommand*>(node);
std::vector<sieve::ASTNode *> children = command->children();
const auto children = command->children();
const size_t size = children.size();

size_t numArguments = 1;
Expand All @@ -266,7 +264,7 @@ bool Command::_validateReplaceCommand(const ASTNode *node) {

bool Command::_validateEncloseCommand(const ASTNode *node) {
const auto *command = dynamic_cast<const ASTCommand*>(node);
std::vector<sieve::ASTNode *> children = command->children();
const auto children = command->children();
const size_t size = children.size();

size_t numArguments = 1;
Expand All @@ -288,7 +286,7 @@ bool Command::_validateEncloseCommand(const ASTNode *node) {

bool Command::_validateExpireCommand(const ASTNode *node) {
const auto *command = dynamic_cast<const ASTCommand *>(node);
std::vector<sieve::ASTNode *> children = command->children();
const auto children = command->children();
const size_t size = children.size();

if (size != 2) {
Expand All @@ -301,7 +299,7 @@ bool Command::_validateExpireCommand(const ASTNode *node) {
return false;
}

const std::unordered_set<std::string> units = {"day", "minute", "second"};
const std::unordered_set<std::string_view> units = {"day", "minute", "second"};
if (units.find(unitChild->value()) == units.end()) {
return false;
}
Expand All @@ -315,7 +313,7 @@ bool Command::_validateExpireCommand(const ASTNode *node) {

bool Command::_validateRedirectCommand(const ASTNode *node) {
const auto *command = dynamic_cast<const ASTCommand*>(node);
std::vector<sieve::ASTNode *> children = command->children();
const auto children = command->children();
const size_t size = children.size();

size_t numArguments = 1;
Expand All @@ -334,13 +332,13 @@ bool Command::_validateRedirectCommand(const ASTNode *node) {

bool Command::_validateSetCommand(const ASTNode *node) {
const auto *command = dynamic_cast<const ASTCommand*>(node);
std::vector<sieve::ASTNode *> children = command->children();
const auto children = command->children();
const size_t size = children.size();

size_t numArguments = 2;
size_t stringArguments = 0;

for (auto it : children) {
for (const auto it : children) {
const ASTTag *tagChild = dynamic_cast<ASTTag *>(it);
const ASTString *stringChild = dynamic_cast<ASTString *>(it);

Expand Down Expand Up @@ -373,8 +371,8 @@ bool Command::_validateSetCommand(const ASTNode *node) {
// TODO: We blindly allow namespaces in variable names even though they are
// disallowed unless the inclusion of an extension enabling that
// namespace is required.
std::string variableName = dynamic_cast<const ASTString*>(children[size-2])->value();
std::regex identifierOrDigit("^([a-zA-Z0-9_\\.]+|[0-9])$");
const auto variableName = std::string{ dynamic_cast<const ASTString*>(children[size-2])->value() };
const std::regex identifierOrDigit("^([a-zA-Z0-9_\\.]+|[0-9])$");

if (!std::regex_match(variableName, identifierOrDigit)) {
return false;
Expand All @@ -385,7 +383,7 @@ bool Command::_validateSetCommand(const ASTNode *node) {

bool Command::_validateVacationCommand(const ASTNode *node) {
const auto *command = dynamic_cast<const ASTCommand*>(node);
std::vector<sieve::ASTNode *> children = command->children();
const auto children = command->children();
const size_t size = children.size();

size_t numArguments = 1;
Expand Down
48 changes: 24 additions & 24 deletions src/AST/Validation/Command.hh
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,33 @@ public:
Command();
~Command() = default;

bool validate(const ASTNode *command) override;
std::string usage(const ASTNode *command) override;
bool validate(const ASTNode *node) override;
std::string usage(const ASTNode *node) override;

private:
// Validation functions
bool _validateAddHeadersCommand(const ASTNode *node);
bool _validateDeleteHeadersCommand(const ASTNode *node);
bool _validateIncludeCommand(const ASTNode *node);
bool _validateIMAP4FlagsAction(const ASTNode *node);
bool _validateFileintoCommand(const ASTNode *node);
bool _validateKeepCommand(const ASTNode *node);
bool _validateReplaceCommand(const ASTNode *node);
bool _validateEncloseCommand(const ASTNode *node);
bool _validateRedirectCommand(const ASTNode *node);
bool _validateSetCommand(const ASTNode *node);
bool _validateVacationCommand(const ASTNode *node);
bool _validateBareCommand(const ASTNode *node);
bool _validateSingleArgumentCommand(const ASTNode *node);
bool _validateSingleStringArgumentCommand(const ASTNode *node);
bool _validateBreakCommand(const ASTNode *node);
bool _validateForeverypartCommand(const ASTNode *node);
bool _validateExtracttextCommand(const ASTNode *node);
bool _validateExpireCommand(const ASTNode *node);
bool _validateNotifyCommand(const ASTNode *node);
bool _validateConvertCommand(const ASTNode *node);

std::map<std::string, bool (Command::*)(const ASTNode *)> _validation_fn_map;
static bool _validateAddHeadersCommand(const ASTNode *node);
static bool _validateDeleteHeadersCommand(const ASTNode *node);
static bool _validateIncludeCommand(const ASTNode *node);
static bool _validateIMAP4FlagsAction(const ASTNode *node);
static bool _validateFileintoCommand(const ASTNode *node);
static bool _validateKeepCommand(const ASTNode *node);
static bool _validateReplaceCommand(const ASTNode *node);
static bool _validateEncloseCommand(const ASTNode *node);
static bool _validateRedirectCommand(const ASTNode *node);
static bool _validateSetCommand(const ASTNode *node);
static bool _validateVacationCommand(const ASTNode *node);
static bool _validateBareCommand(const ASTNode *node);
static bool _validateSingleArgumentCommand(const ASTNode *node);
static bool _validateSingleStringArgumentCommand(const ASTNode *node);
static bool _validateBreakCommand(const ASTNode *node);
static bool _validateForeverypartCommand(const ASTNode *node);
static bool _validateExtracttextCommand(const ASTNode *node);
static bool _validateExpireCommand(const ASTNode *node);
static bool _validateNotifyCommand(const ASTNode *node);
static bool _validateConvertCommand(const ASTNode *node);

std::map<std::string, bool (*)(const ASTNode *)> _validation_fn_map;
std::map<std::string, std::string> _usage_map;
};

Expand Down
2 changes: 1 addition & 1 deletion src/AST/Validation/Tag.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ bool Tag::validate(const ASTNode *node) {
return true;
}

return (this->*_validation_fn_map[tag->value()])(tag);
return (this->_validation_fn_map[tag->value()])(tag);
}

std::string Tag::usage(const ASTNode *node) {
Expand Down
12 changes: 6 additions & 6 deletions src/AST/Validation/Tag.hh
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ public:
Tag();
~Tag() = default;

bool validate(const ASTNode *tag) override;
std::string usage(const ASTNode *tag) override;
bool validate(const ASTNode *node) override;
std::string usage(const ASTNode *node) override;

private:
// Validation functions
bool _validateSingleString(const ASTNode *node);
bool _validateSingleNumeric(const ASTNode *node);
bool _validateList(const ASTNode *node);
static bool _validateSingleString(const ASTNode *node);
static bool _validateSingleNumeric(const ASTNode *node);
static bool _validateList(const ASTNode *node);

std::map<std::string, bool (Tag::*)(const ASTNode *)> _validation_fn_map;
std::map<std::string, bool (*)(const ASTNode *)> _validation_fn_map;
std::map<std::string, std::string> _usage_map;
};

Expand Down
6 changes: 3 additions & 3 deletions src/AST/Validation/Test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ bool Test::validate(const ASTNode *node) {
return true;
}

return (this->*_validation_fn_map[test->value()])(test);
return (this->_validation_fn_map[test->value()])(test);
}

std::string Test::usage(const ASTNode *node) {
Expand Down Expand Up @@ -182,7 +182,7 @@ bool Test::_validateExpirationTest(const ASTNode *node) {
if (tag->value() != ":comparator") return false;
if (asciinumeric->value() != "i;ascii-numeric") return false;

const std::unordered_set<std::string> units = {"day", "minute", "second"};
const std::unordered_set<std::string_view> units = {"day", "minute", "second"};
if (units.find(unit->value()) == units.end()) return false;

return true;
Expand Down Expand Up @@ -259,7 +259,7 @@ bool Test::_validateEnvironmentTest(const ASTNode *node) {
if (name_node == nullptr || (key_list == nullptr && key == nullptr))
return false;

std::string name = name_node->value();
const auto name = name_node->value();

if (name == "domain" ||
name == "host" ||
Expand Down
4 changes: 2 additions & 2 deletions src/Server/MailServer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ MailServer::~MailServer()
close(_socket);
}

std::map<std::string, bool> MailServer::capabilities()
std::map<std::string_view, bool> MailServer::capabilities()
{
auto capabilities = std::map<std::string, bool>();
auto capabilities = std::map<std::string_view, bool>();

this->_connect();

Expand Down
2 changes: 1 addition & 1 deletion src/Server/MailServer.hh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public:
static MailServer create(const std::string& host_with_port);
~MailServer();

std::map<std::string, bool> capabilities();
std::map<std::string_view, bool> capabilities();

protected:
MailServer(std::string hostname, uint32_t port);
Expand Down
Loading

0 comments on commit d204ce4

Please sign in to comment.