Skip to content

Commit c90fb38

Browse files
committed
Fix naming
1 parent 10acf9d commit c90fb38

3 files changed

Lines changed: 14 additions & 18 deletions

File tree

cpp2rust/converter/converter.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2669,21 +2669,21 @@ bool Converter::VisitSwitchStmt(clang::SwitchStmt *stmt) {
26692669

26702670
clang::SwitchCase *default_case = nullptr;
26712671
for (auto *sc : GetTopLevelSwitchCases(stmt)) {
2672-
if (ChainContainsDefault(sc)) {
2672+
if (SwitchCaseContainsDefault(sc)) {
26732673
default_case = sc;
26742674
continue;
26752675
}
26762676
StrCat("v if v == ");
26772677
VisitSwitchCase(sc);
2678-
for (auto *t : GetSwitchArmBody(body, sc)) {
2678+
for (auto *t : GetSwitchCaseBody(body, sc)) {
26792679
Convert(t);
26802680
}
26812681
StrCat("},");
26822682
}
26832683

26842684
if (default_case) {
26852685
StrCat("_ => {");
2686-
for (auto *t : GetSwitchArmBody(body, default_case)) {
2686+
for (auto *t : GetSwitchCaseBody(body, default_case)) {
26872687
Convert(t);
26882688
}
26892689
StrCat("},");

cpp2rust/converter/converter_lib.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ GetTopLevelSwitchCases(clang::SwitchStmt *stmt) {
673673
return cases;
674674
}
675675

676-
bool ChainContainsDefault(clang::SwitchCase *c) {
676+
bool SwitchCaseContainsDefault(clang::SwitchCase *c) {
677677
for (clang::Stmt *cur = c;;) {
678678
if (clang::isa<clang::DefaultStmt>(cur)) {
679679
return true;
@@ -687,18 +687,18 @@ bool ChainContainsDefault(clang::SwitchCase *c) {
687687
return false;
688688
}
689689

690-
clang::Stmt *ChainLeafBody(clang::SwitchCase *c) {
690+
static clang::Stmt *GetLastStmtOfSwitchCase(clang::SwitchCase *c) {
691691
clang::Stmt *cur = c->getSubStmt();
692692
while (auto *sc = clang::dyn_cast<clang::SwitchCase>(cur)) {
693693
cur = sc->getSubStmt();
694694
}
695695
return cur;
696696
}
697697

698-
std::vector<clang::Stmt *> GetSwitchArmBody(clang::CompoundStmt *body,
699-
clang::SwitchCase *head) {
698+
std::vector<clang::Stmt *> GetSwitchCaseBody(clang::CompoundStmt *body,
699+
clang::SwitchCase *head) {
700700
std::vector<clang::Stmt *> out;
701-
out.push_back(ChainLeafBody(head));
701+
out.push_back(GetLastStmtOfSwitchCase(head));
702702
auto it = body->body_begin(), end = body->body_end();
703703
while (it != end && *it != head) {
704704
++it;
@@ -712,7 +712,7 @@ std::vector<clang::Stmt *> GetSwitchArmBody(clang::CompoundStmt *body,
712712
return out;
713713
}
714714

715-
bool SwitchArmHasFallthrough(clang::Stmt *stmt) {
715+
static bool SwitchCaseHasFallthrough(clang::Stmt *stmt) {
716716
if (stmt) {
717717
if (clang::isa<clang::BreakStmt>(stmt) ||
718718
clang::isa<clang::ReturnStmt>(stmt)) {
@@ -725,8 +725,8 @@ bool SwitchArmHasFallthrough(clang::Stmt *stmt) {
725725
bool SwitchHasFallthrough(clang::SwitchStmt *stmt) {
726726
if (auto *body = clang::dyn_cast<clang::CompoundStmt>(stmt->getBody())) {
727727
for (auto top_level_case : GetTopLevelSwitchCases(stmt)) {
728-
auto arm = GetSwitchArmBody(body, top_level_case);
729-
if (arm.empty() || SwitchArmHasFallthrough(arm.back())) {
728+
auto arm = GetSwitchCaseBody(body, top_level_case);
729+
if (arm.empty() || SwitchCaseHasFallthrough(arm.back())) {
730730
return true;
731731
}
732732
}

cpp2rust/converter/converter_lib.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,10 @@ clang::Expr *CreateConversionToBool(clang::Expr *expr, clang::ASTContext &ctx);
157157
std::vector<clang::SwitchCase *>
158158
GetTopLevelSwitchCases(clang::SwitchStmt *stmt);
159159

160-
bool ChainContainsDefault(clang::SwitchCase *c);
160+
bool SwitchCaseContainsDefault(clang::SwitchCase *c);
161161

162-
clang::Stmt *ChainLeafBody(clang::SwitchCase *c);
163-
164-
std::vector<clang::Stmt *> GetSwitchArmBody(clang::CompoundStmt *body,
165-
clang::SwitchCase *head);
166-
167-
bool SwitchArmHasFallthrough(clang::Stmt *stmt);
162+
std::vector<clang::Stmt *> GetSwitchCaseBody(clang::CompoundStmt *body,
163+
clang::SwitchCase *head);
168164

169165
bool SwitchHasFallthrough(clang::SwitchStmt *stmt);
170166

0 commit comments

Comments
 (0)