File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1896,9 +1896,18 @@ void Converter::EmitFnPtrCall(clang::Expr *callee) {
18961896 StrCat (" .unwrap()" );
18971897}
18981898
1899+ std::string Converter::GetFunctionRefName (const clang::FunctionDecl *fn_decl) {
1900+ if (auto *method = clang::dyn_cast<clang::CXXMethodDecl>(fn_decl);
1901+ method && method->isStatic ()) {
1902+ return std::format (" {}::{}" , GetRecordName (method->getParent ()),
1903+ GetMethodName (method));
1904+ }
1905+ return Mapper::MapFunctionName (fn_decl);
1906+ }
1907+
18991908void Converter::ConvertFunctionToFunctionPointer (
19001909 const clang::FunctionDecl *fn_decl) {
1901- StrCat (std::format (" Some({})" , Mapper::MapFunctionName (fn_decl)));
1910+ StrCat (std::format (" Some({})" , GetFunctionRefName (fn_decl)));
19021911 computed_expr_type_ = ComputedExprType::FreshPointer;
19031912}
19041913
@@ -3015,8 +3024,7 @@ std::string Converter::ConvertDeclRefExpr(clang::DeclRefExpr *expr) {
30153024 if (auto *function = decl->getAsFunction ()) {
30163025 if (auto method = clang::dyn_cast<clang::CXXMethodDecl>(function)) {
30173026 if (method->isStatic ()) {
3018- return std::format (" {}::{}" , GetRecordName (method->getParent ()),
3019- GetNamedDeclAsString (method));
3027+ return GetFunctionRefName (method);
30203028 }
30213029 }
30223030 return GetNamedDeclAsString (function->getCanonicalDecl ());
Original file line number Diff line number Diff line change @@ -314,6 +314,8 @@ class Converter : public clang::RecursiveASTVisitor<Converter> {
314314 virtual void
315315 ConvertFunctionToFunctionPointer (const clang::FunctionDecl *fn_decl);
316316
317+ std::string GetFunctionRefName (const clang::FunctionDecl *fn_decl);
318+
317319 std::string ConvertFnPtrCallee (clang::Expr *arg);
318320 virtual std::string ConvertFnPtrPlaceholder (clang::Expr *arg);
319321
Original file line number Diff line number Diff line change @@ -1352,7 +1352,7 @@ void ConverterRefCount::ConvertFunctionToFunctionPointer(
13521352 StrCat (std::format (" FnPtr::<{}>::new({})" ,
13531353 ConvertFunctionPointerType (
13541354 fn_decl->getType ()->getAs <clang::FunctionProtoType>()),
1355- Mapper::MapFunctionName (fn_decl)));
1355+ GetFunctionRefName (fn_decl)));
13561356 computed_expr_type_ = ComputedExprType::FreshPointer;
13571357}
13581358
Original file line number Diff line number Diff line change @@ -76,15 +76,15 @@ pub fn main() {
7676}
7777fn main_0 ( ) -> i32 {
7878 let p1: Value < FnPtr < fn ( i32 ) -> i32 > > =
79- Rc :: new ( RefCell :: new ( ( FnPtr :: < fn ( i32 ) -> i32 > :: new ( pick ) ) ) ) ;
79+ Rc :: new ( RefCell :: new ( ( FnPtr :: < fn ( i32 ) -> i32 > :: new ( S :: pick_i32 ) ) ) ) ;
8080 let p2: Value < FnPtr < fn ( i32 ) -> i32 > > =
81- Rc :: new ( RefCell :: new ( FnPtr :: < fn ( i32 ) -> i32 > :: new ( solo) ) ) ;
81+ Rc :: new ( RefCell :: new ( FnPtr :: < fn ( i32 ) -> i32 > :: new ( S :: solo) ) ) ;
8282 assert ! ( ( ( { ( * ( * p1. borrow( ) ) ) ( 5 , ) } ) == 6 ) ) ;
8383 assert ! ( ( ( { ( * ( * p2. borrow( ) ) ) ( 5 , ) } ) == 8 ) ) ;
84- assert ! ( ( ( { S :: pick ( 5_i64 , ) } ) == 7 ) ) ;
84+ assert ! ( ( ( { S :: pick_i64 ( 5_i64 , ) } ) == 7 ) ) ;
8585 let h3: Value < Handler > = Rc :: new ( RefCell :: new ( Handler {
8686 tag : Rc :: new ( RefCell :: new ( 3 ) ) ,
87- cb : Rc :: new ( RefCell :: new ( ( FnPtr :: < fn ( i32 ) -> i32 > :: new ( pick ) ) ) ) ,
87+ cb : Rc :: new ( RefCell :: new ( ( FnPtr :: < fn ( i32 ) -> i32 > :: new ( S :: pick_i32 ) ) ) ) ,
8888 } ) ) ;
8989 assert ! ( ( ( { ( * ( * ( * h3. borrow( ) ) . cb. borrow( ) ) ) ( 1 , ) } ) == 2 ) ) ;
9090 let h1: Value < Handler > = Rc :: new ( RefCell :: new ( Handler {
Original file line number Diff line number Diff line change @@ -47,14 +47,14 @@ pub fn main() {
4747 }
4848}
4949unsafe fn main_0 ( ) -> i32 {
50- let mut p1: Option < unsafe fn ( i32 ) -> i32 > = ( Some ( pick ) ) ;
51- let mut p2: Option < unsafe fn ( i32 ) -> i32 > = Some ( solo) ;
50+ let mut p1: Option < unsafe fn ( i32 ) -> i32 > = ( Some ( S :: pick_i32 ) ) ;
51+ let mut p2: Option < unsafe fn ( i32 ) -> i32 > = Some ( S :: solo) ;
5252 assert ! ( ( ( unsafe { ( p1) . unwrap( ) ( 5 , ) } ) == ( 6 ) ) ) ;
5353 assert ! ( ( ( unsafe { ( p2) . unwrap( ) ( 5 , ) } ) == ( 8 ) ) ) ;
54- assert ! ( ( ( unsafe { S :: pick ( 5_i64 , ) } ) == ( 7 ) ) ) ;
54+ assert ! ( ( ( unsafe { S :: pick_i64 ( 5_i64 , ) } ) == ( 7 ) ) ) ;
5555 let mut h3: Handler = Handler {
5656 tag : 3 ,
57- cb : ( Some ( pick ) ) ,
57+ cb : ( Some ( S :: pick_i32 ) ) ,
5858 } ;
5959 assert ! ( ( ( unsafe { ( h3. cb) . unwrap( ) ( 1 , ) } ) == ( 2 ) ) ) ;
6060 let mut h1: Handler = Handler {
You can’t perform that action at this time.
0 commit comments