Skip to content

Commit

Permalink
Fix -readability-else-after-return
Browse files Browse the repository at this point in the history
  • Loading branch information
Baltoli committed Jan 16, 2024
1 parent b6697a8 commit 2d04fe9
Show file tree
Hide file tree
Showing 32 changed files with 509 additions and 539 deletions.
1 change: 0 additions & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ Checks:
-readability-magic-numbers
-readability-identifier-length
-readability-implicit-bool-conversion
-readability-else-after-return
-readability-function-cognitive-complexity
-readability-named-parameter
-readability-suspicious-call-argument
Expand Down
5 changes: 2 additions & 3 deletions bindings/core/src/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,9 @@ block *simplify_to_term(

if (is_sort_kitem(sort) || is_sort_k(sort)) {
return construct_term(pattern);
} else {
auto rawTerm = make_rawTerm(pattern, sort, kitem_sort);
} auto rawTerm = make_rawTerm(pattern, sort, kitem_sort);
return construct_term(rawTerm);
}

}

std::shared_ptr<KOREPattern> simplify(
Expand Down
69 changes: 30 additions & 39 deletions lib/ast/AST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ using namespace kllvm;
sptr<KOREPattern> KOREPattern::load(std::string const &filename) {
if (has_binary_kore_header(filename)) {
return deserialize_pattern(filename);
} else {
return parser::KOREParser(filename).pattern();
}
return parser::KOREParser(filename).pattern();
}

std::string kllvm::decodeKore(std::string kore) {
Expand Down Expand Up @@ -1004,14 +1003,12 @@ sptr<KOREPattern> KORECompositePattern::filterSubstitution(
unit->getConstructor()->addFormalArgument(
constructor->getFormalArguments()[1]);
return unit;
} else {
return shared_from_this();
}
} else {
return shared_from_this();
}
} else if (
constructor->getName() == "\\and" || constructor->getName() == "\\or") {
return shared_from_this();
}
if (constructor->getName() == "\\and" || constructor->getName() == "\\or") {
sptr<KORECompositePattern> result
= KORECompositePattern::Create(constructor.get());
for (auto &arg : arguments) {
Expand Down Expand Up @@ -1091,27 +1088,25 @@ sptr<KOREPattern> KORECompositePattern::unflattenAndOr() {
&& arguments.size() != 2) {
if (arguments.size() == 1) {
return arguments[0]->unflattenAndOr();
} else {
auto accum = arguments[0]->unflattenAndOr();

for (auto i = 1U; i < arguments.size(); i++) {
auto new_accum = KORECompositePattern::Create(constructor.get());
new_accum->addArgument(accum);
new_accum->addArgument(arguments[i]->unflattenAndOr());
accum = ptr<KOREPattern>(new_accum.release());
}

return accum;
}
} else {
auto result = KORECompositePattern::Create(constructor.get());
auto accum = arguments[0]->unflattenAndOr();

for (auto &arg : arguments) {
result->addArgument(arg->unflattenAndOr());
for (auto i = 1U; i < arguments.size(); i++) {
auto new_accum = KORECompositePattern::Create(constructor.get());
new_accum->addArgument(accum);
new_accum->addArgument(arguments[i]->unflattenAndOr());
accum = ptr<KOREPattern>(new_accum.release());
}

return result;
return accum;
}
auto result = KORECompositePattern::Create(constructor.get());

for (auto &arg : arguments) {
result->addArgument(arg->unflattenAndOr());
}

return result;
}

sptr<KOREPattern> KORECompositePattern::expandMacros(
Expand Down Expand Up @@ -1166,10 +1161,9 @@ bool KOREVariablePattern::matches(
sptr<KOREPattern> subject) {
if (subst[name->getName()]) {
return ast_to_string(*subst[name->getName()]) == ast_to_string(*subject);
} else {
subst[name->getName()] = subject;
return true;
}
subst[name->getName()] = subject;
return true;
}

bool KORECompositePattern::matches(
Expand All @@ -1195,18 +1189,18 @@ bool KORECompositePattern::matches(
ba->getConstructor()->addArgument(b);
ba->addArgument(arguments[0]);
return ba->matches(subst, subsorts, overloads, subj->getArguments()[0]);
} else if (
subsorts.count(a.get()) && subsorts.at(a.get()).count(b.get())) {
}
if (subsorts.count(a.get()) && subsorts.at(a.get()).count(b.get())) {
sptr<KORECompositePattern> ab = KORECompositePattern::Create("inj");
ab->getConstructor()->addFormalArgument(a);
ab->getConstructor()->addFormalArgument(b);
ab->getConstructor()->addArgument(a);
ab->addArgument(subj->getArguments()[0]);
return arguments[0]->matches(subst, subsorts, overloads, ab);
} else {
return false;
}
} else if (subj->getConstructor()->getName() == "inj") {
return false;
}
if (subj->getConstructor()->getName() == "inj") {
sptr<KOREPattern> child = subj->getArguments()[0];
if (auto *composite = dynamic_cast<KORECompositePattern *>(child.get())) {
if (overloads.count(composite->getConstructor())
Expand All @@ -1232,15 +1226,12 @@ bool KORECompositePattern::matches(
}
}
return this->matches(subst, subsorts, overloads, greater);
} else {
return false;
}
} else {
return false;
}
} else {
return false;
}
return false;
}
if (subj->arguments.size() != arguments.size()) {
return false;
Expand Down Expand Up @@ -1319,12 +1310,12 @@ bool KOREAxiomDeclaration::isTopAxiom() const {
}
}
return false;
} else if (
top->getConstructor()->getName() == "\\rewrites"
}
if (top->getConstructor()->getName() == "\\rewrites"
&& top->getArguments().size() == 2) {
return true;
} else if (
top->getConstructor()->getName() == "\\and"
}
if (top->getConstructor()->getName() == "\\and"
&& top->getArguments().size() == 2) {
return true;
}
Expand Down
7 changes: 3 additions & 4 deletions lib/ast/pattern_matching.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ getPatternsImpl(KOREPattern *pat, std::vector<KOREPattern *> &result) {
if (composite->getConstructor()->getName() == "\\top"
&& composite->getArguments().empty()) {
return result;
} else if (
composite->getConstructor()->getName() == "\\and"
}
if (composite->getConstructor()->getName() == "\\and"
&& composite->getArguments().size() == 2) {
if (auto *firstChild = dynamic_cast<KORECompositePattern *>(
composite->getArguments()[0].get())) {
Expand Down Expand Up @@ -66,9 +66,8 @@ getBuiltin(std::shared_ptr<KOREPattern> const &term) {

if (!lhs->getConstructor()->isBuiltin()) {
return lhs;
} else {
return comp->getArguments()[1];
}
return comp->getArguments()[1];
}

[[maybe_unused]] std::optional<std::vector<KOREPattern *>>
Expand Down
6 changes: 2 additions & 4 deletions lib/binary/serializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ serializer::serializer()
serializer::serializer(flags f)
: use_header_(!(f & DROP_HEADER))
, use_arity_(!(f & DROP_ARITY))
,
direct_string_prefix_{0x01}
, direct_string_prefix_{0x01}
, backref_string_prefix_{0x02}
, next_idx_(0)
{
, next_idx_(0) {
if (use_header_) {
emit_header_and_version();
emit_zero_size();
Expand Down
7 changes: 2 additions & 5 deletions lib/codegen/CreateStaticTerm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,12 @@ CreateStaticTerm::operator()(KOREPattern *pattern) {
if (tag != (uint32_t)-1 && tag >= inj->getFirstTag()
&& tag <= inj->getLastTag()) {
return std::make_pair(val.first, true);
} else {
return std::make_pair(notInjectionCase(constructor, val.first), true);
}
} else {
return std::make_pair(notInjectionCase(constructor, val.first), true);
}
} else {
return std::make_pair(notInjectionCase(constructor, nullptr), false);
return std::make_pair(notInjectionCase(constructor, val.first), true);
}
return std::make_pair(notInjectionCase(constructor, nullptr), false);
}
assert(false && "Something went wrong when trying to allocate a static term");
abort();
Expand Down
Loading

0 comments on commit 2d04fe9

Please sign in to comment.