@@ -192,15 +192,15 @@ std::string ConverterRefCount::BuildFnAdapter(
192192 closure += " { " ;
193193
194194 // Build adapter body: src_fn(convert(a0), convert(a1), ...)
195- closure += GetNamedDeclAsString (src_fn-> getCanonicalDecl () ) + " (" ;
195+ closure += Mapper::GetFnRefName (src_fn) + " (" ;
196196 for (unsigned i = 0 ; i < src_proto->getNumParams (); ++i) {
197197 auto src_pty = src_proto->getParamType (i);
198198 auto tgt_pty = target_proto->getParamType (i);
199199 if (ToString (src_pty) == ToString (tgt_pty)) {
200200 closure += std::format (" a{}" , i);
201201 } else if (src_pty->isPointerType () && tgt_pty->isVoidPointerType ()) {
202202 closure += std::format (" a{}.cast::<{}>().unwrap()" , i,
203- ToString (src_pty-> getPointeeType () ));
203+ GetPointeeRustType (src_pty));
204204 } else if (src_pty->isVoidPointerType () && tgt_pty->isPointerType ()) {
205205 closure += std::format (" a{}.to_any()" , i);
206206 } else {
@@ -622,19 +622,18 @@ bool ConverterRefCount::VisitDeclRefExpr(clang::DeclRefExpr *expr) {
622622 }
623623 }
624624
625- if (Mapper::Contains (expr)) {
625+ auto str = ConvertDeclRefExpr (expr);
626+ auto decl = expr->getDecl ();
627+
628+ if (!(clang::isa<clang::FunctionDecl>(decl) && isAddrOf ()) &&
629+ Mapper::Contains (expr)) {
626630 StrCat (GetMappedAsString (expr));
627631 return false ;
628632 }
629633
630- auto str = ConvertDeclRefExpr (expr);
631- auto decl = expr->getDecl ();
632-
633- if (clang::isa<clang::FunctionDecl>(decl)) {
634+ if (auto *fn_decl = clang::dyn_cast<clang::FunctionDecl>(decl)) {
634635 if (isAddrOf ()) {
635- auto proto = decl->getType ()->getAs <clang::FunctionProtoType>();
636- auto fn_type = GetFnTypeString (proto);
637- StrCat (std::format (" fn_ptr!({}, {})" , str, fn_type));
636+ EmitFnAsValue (fn_decl);
638637 } else {
639638 StrCat (str);
640639 }
@@ -1030,6 +1029,12 @@ void ConverterRefCount::EmitFnPtrCall(clang::Expr *callee) {
10301029 StrCat (" .call()" );
10311030}
10321031
1032+ void ConverterRefCount::EmitFnAsValue (const clang::FunctionDecl *fn_decl) {
1033+ StrCat (std::format (
1034+ " fn_ptr!({}, {})" , Mapper::GetFnRefName (fn_decl),
1035+ GetFnTypeString (fn_decl->getType ()->getAs <clang::FunctionProtoType>())));
1036+ }
1037+
10331038std::string ConverterRefCount::GetFunctionPointerDefaultAsString (
10341039 clang::QualType qual_type) {
10351040 return " FnPtr::null()" ;
0 commit comments