Skip to content

Commit 0bd0990

Browse files
committed
Get fully qualified name of translation rule
1 parent 7862218 commit 0bd0990

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

cpp2rust/converter/mapper.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <llvm/Support/ThreadPool.h>
99

1010
#include <atomic>
11+
#include <format>
1112
#include <mutex>
1213
#include <regex>
1314
#include <utility>
@@ -600,6 +601,17 @@ std::string normalizeTranslationRule(std::string rule) {
600601
return rule;
601602
}
602603

604+
std::string GetRulePathForFunction(const clang::FunctionDecl *decl,
605+
const std::string &model_suffix) {
606+
assert(decl);
607+
auto it = exprs_.find(ToString(decl));
608+
if (it == exprs_.end()) {
609+
return "";
610+
}
611+
auto &tgt = it->second;
612+
return std::format("rules::{}_{}::{}", tgt.module, model_suffix, tgt.name);
613+
}
614+
603615
} // namespace
604616

605617
bool Contains(clang::QualType qual_type) {
@@ -615,6 +627,21 @@ const TranslationRule::ExprTgt *GetExprTgt(const clang::Expr *expr) {
615627
return nullptr;
616628
}
617629

630+
std::string GetFnRefName(const clang::FunctionDecl *decl) {
631+
assert(decl);
632+
if (model_ == Model::kRefCount) {
633+
auto refcount_path = GetRulePathForFunction(decl, "tgt_refcount");
634+
if (!refcount_path.empty()) {
635+
return refcount_path;
636+
}
637+
}
638+
auto unsafe_path = GetRulePathForFunction(decl, "tgt_unsafe");
639+
if (!unsafe_path.empty()) {
640+
return unsafe_path;
641+
}
642+
return GetNamedDeclAsString(decl->getCanonicalDecl());
643+
}
644+
618645
std::string InstantiateTemplate(const clang::Expr *expr,
619646
const std::string &text) {
620647
auto it = search(expr);

cpp2rust/converter/mapper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ bool Contains(const clang::Expr *expr);
1919

2020
std::string Map(clang::QualType qual_type);
2121
const TranslationRule::ExprTgt *GetExprTgt(const clang::Expr *expr);
22+
std::string GetFnRefName(const clang::FunctionDecl *decl);
2223
std::string InstantiateTemplate(const clang::Expr *expr,
2324
const std::string &text);
2425
bool ReturnsPointer(const clang::Expr *expr);

0 commit comments

Comments
 (0)