Skip to content

Commit 5e2b3f2

Browse files
committed
Extract emission of accessor in separate function
1 parent 1198c90 commit 5e2b3f2

2 files changed

Lines changed: 25 additions & 20 deletions

File tree

‎cpp2rust/converter/models/converter_refcount.cpp‎

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,6 +1484,28 @@ bool ConverterRefCount::VisitInitListExpr(clang::InitListExpr *expr) {
14841484
return false;
14851485
}
14861486

1487+
void ConverterRefCount::ConvertUnionMemberAccessor(clang::MemberExpr *expr) {
1488+
std::string str;
1489+
{
1490+
Buffer buf(*this);
1491+
PushExprKind push(*this, isLValue() ? ExprKind::LValue : ExprKind::RValue);
1492+
Converter::ConvertMemberExpr(expr);
1493+
str = std::move(buf).str();
1494+
}
1495+
str += "()";
1496+
1497+
if (isAddrOf()) {
1498+
StrCat(str);
1499+
computed_expr_type_ = ComputedExprType::Pointer;
1500+
return;
1501+
}
1502+
if (isLValue()) {
1503+
pending_deref_.set(str);
1504+
return;
1505+
}
1506+
StrCat(DerefPtrExpr(str, expr->getMemberDecl()->getType()));
1507+
}
1508+
14871509
bool ConverterRefCount::VisitMemberExpr(clang::MemberExpr *expr) {
14881510
auto *member = expr->getMemberDecl();
14891511
bool known = Mapper::Contains(expr);
@@ -1506,26 +1528,7 @@ bool ConverterRefCount::VisitMemberExpr(clang::MemberExpr *expr) {
15061528
if (auto *parent =
15071529
clang::dyn_cast<clang::RecordDecl>(member->getDeclContext());
15081530
parent && parent->isUnion() && clang::isa<clang::FieldDecl>(member)) {
1509-
std::string str;
1510-
{
1511-
Buffer buf(*this);
1512-
PushExprKind push(*this,
1513-
isLValue() ? ExprKind::LValue : ExprKind::RValue);
1514-
Converter::ConvertMemberExpr(expr);
1515-
str = std::move(buf).str();
1516-
}
1517-
str += "()";
1518-
1519-
if (isAddrOf()) {
1520-
StrCat(str);
1521-
computed_expr_type_ = ComputedExprType::Pointer;
1522-
return false;
1523-
}
1524-
if (isLValue()) {
1525-
pending_deref_.set(str);
1526-
return false;
1527-
}
1528-
StrCat(DerefPtrExpr(str, member->getType()));
1531+
ConvertUnionMemberAccessor(expr);
15291532
return false;
15301533
}
15311534

‎cpp2rust/converter/models/converter_refcount.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ class ConverterRefCount final : public Converter {
103103

104104
bool VisitMemberExpr(clang::MemberExpr *expr) override;
105105

106+
void ConvertUnionMemberAccessor(clang::MemberExpr *expr);
107+
106108
bool VisitCXXNewExpr(clang::CXXNewExpr *expr) override;
107109

108110
bool VisitCXXDeleteExpr(clang::CXXDeleteExpr *expr) override;

0 commit comments

Comments
 (0)