Skip to content

Commit 5d3f9d6

Browse files
committed
Extract emission of accessor in separate function
1 parent 47664ea commit 5d3f9d6

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
@@ -1493,6 +1493,28 @@ bool ConverterRefCount::VisitInitListExpr(clang::InitListExpr *expr) {
14931493
return false;
14941494
}
14951495

1496+
void ConverterRefCount::ConvertUnionMemberAccessor(clang::MemberExpr *expr) {
1497+
std::string str;
1498+
{
1499+
Buffer buf(*this);
1500+
PushExprKind push(*this, isLValue() ? ExprKind::LValue : ExprKind::RValue);
1501+
Converter::ConvertMemberExpr(expr);
1502+
str = std::move(buf).str();
1503+
}
1504+
str += "()";
1505+
1506+
if (isAddrOf()) {
1507+
StrCat(str);
1508+
computed_expr_type_ = ComputedExprType::Pointer;
1509+
return;
1510+
}
1511+
if (isLValue()) {
1512+
pending_deref_.set(str);
1513+
return;
1514+
}
1515+
StrCat(DerefPtrExpr(str, expr->getMemberDecl()->getType()));
1516+
}
1517+
14961518
bool ConverterRefCount::VisitMemberExpr(clang::MemberExpr *expr) {
14971519
auto *member = expr->getMemberDecl();
14981520
bool known = Mapper::Contains(expr);
@@ -1515,26 +1537,7 @@ bool ConverterRefCount::VisitMemberExpr(clang::MemberExpr *expr) {
15151537
if (auto *parent =
15161538
clang::dyn_cast<clang::RecordDecl>(member->getDeclContext());
15171539
parent && parent->isUnion() && clang::isa<clang::FieldDecl>(member)) {
1518-
std::string str;
1519-
{
1520-
Buffer buf(*this);
1521-
PushExprKind push(*this,
1522-
isLValue() ? ExprKind::LValue : ExprKind::RValue);
1523-
Converter::ConvertMemberExpr(expr);
1524-
str = std::move(buf).str();
1525-
}
1526-
str += "()";
1527-
1528-
if (isAddrOf()) {
1529-
StrCat(str);
1530-
computed_expr_type_ = ComputedExprType::Pointer;
1531-
return false;
1532-
}
1533-
if (isLValue()) {
1534-
pending_deref_.set(str);
1535-
return false;
1536-
}
1537-
StrCat(DerefPtrExpr(str, member->getType()));
1540+
ConvertUnionMemberAccessor(expr);
15381541
return false;
15391542
}
15401543

‎cpp2rust/converter/models/converter_refcount.h‎

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

106106
bool VisitMemberExpr(clang::MemberExpr *expr) override;
107107

108+
void ConvertUnionMemberAccessor(clang::MemberExpr *expr);
109+
108110
bool VisitCXXNewExpr(clang::CXXNewExpr *expr) override;
109111

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

0 commit comments

Comments
 (0)