@@ -6,7 +6,7 @@ use std::rc::Rc;
6
6
7
7
use clang:: { Availability , Entity , EntityKind , ExceptionSpecification } ;
8
8
pub use desc:: { FuncCppBody , FuncDesc , FuncRustBody , FuncRustExtern } ;
9
- pub use func_id :: FuncId ;
9
+ pub use func_matcher :: { FuncId , FuncMatchProperties , FuncMatcher , Pred } ;
10
10
pub use kind:: { FuncKind , OperatorKind , ReturnKind } ;
11
11
use once_cell:: sync:: Lazy ;
12
12
use regex:: bytes:: Regex ;
@@ -27,7 +27,7 @@ use crate::{
27
27
} ;
28
28
29
29
mod desc;
30
- mod func_id ;
30
+ mod func_matcher ;
31
31
mod kind;
32
32
mod slice_arg_finder;
33
33
@@ -611,6 +611,10 @@ impl<'tu, 'ge> Func<'tu, 'ge> {
611
611
}
612
612
}
613
613
614
+ pub fn matcher ( & self ) -> FuncMatchProperties {
615
+ FuncMatchProperties :: new ( self , self . cpp_name ( CppNameStyle :: Reference ) )
616
+ }
617
+
614
618
pub fn rust_body ( & self ) -> & FuncRustBody {
615
619
match self {
616
620
Self :: Clang { .. } => & FuncRustBody :: Auto ,
@@ -708,13 +712,23 @@ impl Element for Func<'_, '_> {
708
712
}
709
713
710
714
fn cpp_name ( & self , style : CppNameStyle ) -> Cow < str > {
711
- let decl_name = if self . kind ( ) . as_conversion_method ( ) . is_some ( ) {
712
- format ! ( "operator {}" , self . return_type_ref( ) . cpp_name( CppNameStyle :: Reference ) ) . into ( )
713
- } else {
714
- match self {
715
- & Self :: Clang { entity, .. } => DefaultElement :: cpp_name ( self , entity, CppNameStyle :: Declaration ) ,
716
- Self :: Desc ( desc) => desc. cpp_name . cpp_name_from_fullname ( CppNameStyle :: Declaration ) . into ( ) ,
715
+ let decl_name = match self {
716
+ & Self :: Clang { entity, gen_env, .. } => {
717
+ if matches ! ( entity. get_kind( ) , EntityKind :: ConversionFunction ) {
718
+ // this is to avoid calling `return_type_ref()` just to get the name of the type otherwise it causes infinite recursion
719
+ // together with the call `cpp_name(Reference)` from `matcher()`
720
+ let ret_type = TypeRef :: new ( entity. get_result_type ( ) . expect ( "Can't get result type" ) , gen_env) ;
721
+ let ret_type = ret_type
722
+ . kind ( )
723
+ . as_reference ( )
724
+ . map ( |tref| tref. into_owned ( ) )
725
+ . unwrap_or ( ret_type) ;
726
+ format ! ( "operator {}" , ret_type. cpp_name( CppNameStyle :: Reference ) ) . into ( )
727
+ } else {
728
+ DefaultElement :: cpp_name ( self , entity, CppNameStyle :: Declaration )
729
+ }
717
730
}
731
+ Self :: Desc ( desc) => desc. cpp_name . cpp_name_from_fullname ( CppNameStyle :: Declaration ) . into ( ) ,
718
732
} ;
719
733
match style {
720
734
CppNameStyle :: Declaration => decl_name,
@@ -742,7 +756,11 @@ impl<'me> NameDebug<'me> for &'me Func<'_, '_> {
742
756
. iter ( )
743
757
. map ( |a| format ! ( "{:?}" , a. type_ref( ) . render_lane( ) ) )
744
758
. join ( ", " ) ;
745
- format ! ( "// {name}({render_lanes}) {func_id} {location}" , func_id = self . func_id( ) )
759
+ format ! (
760
+ "// {name}({render_lanes}) {location}\n \
761
+ // {func_match}",
762
+ func_match = self . matcher( ) . dump( )
763
+ )
746
764
} else {
747
765
"" . to_string ( )
748
766
}
0 commit comments