@@ -6,8 +6,21 @@ namespace CppSharp.Passes
66{
77 public class ParamTypeToInterfacePass : TranslationUnitPass
88 {
9+ public ParamTypeToInterfacePass ( )
10+ {
11+ VisitOptions . VisitClassBases = false ;
12+ VisitOptions . VisitClassFields = false ;
13+ VisitOptions . VisitEventParameters = false ;
14+ VisitOptions . VisitNamespaceEnums = false ;
15+ VisitOptions . VisitNamespaceEvents = false ;
16+ VisitOptions . VisitTemplateArguments = false ;
17+ }
18+
919 public override bool VisitFunctionDecl ( Function function )
1020 {
21+ if ( ! base . VisitFunctionDecl ( function ) )
22+ return false ;
23+
1124 if ( ! function . IsOperator || function . Parameters . Count > 1 )
1225 {
1326 var originalReturnType = function . OriginalReturnType ;
@@ -17,32 +30,57 @@ public override bool VisitFunctionDecl(Function function)
1730
1831 if ( function . OperatorKind != CXXOperatorKind . Conversion &&
1932 function . OperatorKind != CXXOperatorKind . ExplicitConversion )
20- foreach ( var parameter in function . Parameters . Where ( p => p . Kind != ParameterKind . OperatorParameter ) )
33+ foreach ( var parameter in function . Parameters . Where (
34+ p => p . Kind != ParameterKind . OperatorParameter ) )
2135 {
2236 var qualifiedType = parameter . QualifiedType ;
2337 ChangeToInterfaceType ( ref qualifiedType ) ;
2438 parameter . QualifiedType = qualifiedType ;
2539 }
2640
27- return base . VisitFunctionDecl ( function ) ;
41+ return true ;
42+ }
43+
44+ public override bool VisitProperty ( Property property )
45+ {
46+ if ( ! base . VisitProperty ( property ) )
47+ return false ;
48+
49+ var type = property . QualifiedType ;
50+ ChangeToInterfaceType ( ref type ) ;
51+ property . QualifiedType = type ;
52+ return true ;
2853 }
2954
3055 private static void ChangeToInterfaceType ( ref QualifiedType type )
3156 {
32- var tagType = ( type . Type . GetFinalPointee ( ) ?? type . Type ) as TagType ;
33- if ( tagType != null )
57+ var finalType = ( type . Type . GetFinalPointee ( ) ?? type . Type ) . Desugar ( ) ;
58+ Class @class ;
59+ if ( ! finalType . TryGetClass ( out @class ) )
60+ return ;
61+
62+ var specialization = @class as ClassTemplateSpecialization ;
63+ Class @interface = null ;
64+ if ( specialization == null )
3465 {
35- var @class = tagType . Declaration as Class ;
36- if ( @class != null )
37- {
38- var @interface = @class . Namespace . Classes . Find ( c => c . OriginalClass == @class ) ;
39- if ( @interface != null )
40- {
41- type . Type = ( Type ) type . Type . Clone ( ) ;
42- ( ( TagType ) ( type . Type . GetFinalPointee ( ) ?? type . Type ) ) . Declaration = @interface ;
43- }
44- }
66+ @interface = @class . Namespace . Classes . Find (
67+ c => c . OriginalClass == @class && c . IsInterface ) ;
4568 }
69+ else
70+ {
71+ Class template = specialization . TemplatedDecl . TemplatedClass ;
72+ Class templatedInterface = @class . Namespace . Classes . Find (
73+ c => c . OriginalClass == template && c . IsInterface ) ;
74+ if ( templatedInterface != null )
75+ @interface = templatedInterface . Specializations . FirstOrDefault (
76+ s => s . OriginalClass == specialization ) ;
77+ }
78+ if ( @interface == null )
79+ return ;
80+
81+ type . Type = ( Type ) type . Type . Clone ( ) ;
82+ finalType = ( type . Type . GetFinalPointee ( ) ?? type . Type ) . Desugar ( ) ;
83+ finalType . TryGetClass ( out @class , @interface ) ;
4684 }
4785 }
4886}
0 commit comments