Skip to content

Commit 1e0794a

Browse files
committed
Add ShouldReplaceWithMappedBody
1 parent a929df9 commit 1e0794a

3 files changed

Lines changed: 14 additions & 7 deletions

File tree

cpp2rust/converter/converter.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2033,8 +2033,7 @@ std::string Converter::ConvertDeclRefExpr(clang::DeclRefExpr *expr) {
20332033
}
20342034

20352035
auto *decl = expr->getDecl();
2036-
if (!(clang::isa<clang::FunctionDecl>(decl) && isAddrOf()) &&
2037-
Mapper::Contains(expr)) {
2036+
if (ShouldReplaceWithMappedBody(expr)) {
20382037
return GetMappedAsString(expr);
20392038
} else if (auto *function = decl->getAsFunction()) {
20402039
if (auto method = clang::dyn_cast<clang::CXXMethodDecl>(function)) {
@@ -3430,6 +3429,13 @@ bool Converter::isCallee() const {
34303429
return !curr_expr_kind_.empty() && curr_expr_kind_.back() == ExprKind::Callee;
34313430
}
34323431

3432+
bool Converter::ShouldReplaceWithMappedBody(clang::DeclRefExpr *expr) const {
3433+
if (clang::isa<clang::FunctionDecl>(expr->getDecl()) && isAddrOf()) {
3434+
return false;
3435+
}
3436+
return Mapper::Contains(expr);
3437+
}
3438+
34333439
void Converter::SetFresh() {
34343440
switch (computed_expr_type_) {
34353441
case ComputedExprType::Value:

cpp2rust/converter/converter.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,8 @@ class Converter : public clang::RecursiveASTVisitor<Converter> {
455455

456456
virtual bool RecordDerivesDefault(const clang::CXXRecordDecl *decl);
457457

458+
bool ShouldReplaceWithMappedBody(clang::DeclRefExpr *expr) const;
459+
458460
std::string *rs_code_;
459461
clang::ASTContext &ctx_;
460462
clang::FunctionDecl *curr_function_ = nullptr;

cpp2rust/converter/models/converter_refcount.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -626,15 +626,14 @@ bool ConverterRefCount::VisitDeclRefExpr(clang::DeclRefExpr *expr) {
626626
}
627627
}
628628

629-
auto str = ConvertDeclRefExpr(expr);
630-
auto decl = expr->getDecl();
631-
632-
if (!(clang::isa<clang::FunctionDecl>(decl) && isAddrOf()) &&
633-
Mapper::Contains(expr)) {
629+
if (ShouldReplaceWithMappedBody(expr)) {
634630
StrCat(GetMappedAsString(expr));
635631
return false;
636632
}
637633

634+
auto str = ConvertDeclRefExpr(expr);
635+
auto decl = expr->getDecl();
636+
638637
if (auto fn_decl = clang::dyn_cast<clang::FunctionDecl>(decl)) {
639638
if (isAddrOf()) {
640639
ConvertFunctionToFunctionPointer(fn_decl);

0 commit comments

Comments
 (0)