@@ -32,8 +32,7 @@ static bool IsProtectedClassMember(Declaration decl)
32
32
if ( decl . Access != AccessSpecifier . Protected )
33
33
return false ;
34
34
35
- var @class = decl . Namespace as Class ;
36
- return @class != null && @class . IsStatic ;
35
+ return decl . Namespace is Class { IsStatic : true } ;
37
36
}
38
37
39
38
static void SetDeclarationAccessToPrivate ( Declaration decl )
@@ -42,7 +41,7 @@ static void SetDeclarationAccessToPrivate(Declaration decl)
42
41
// as an internal in the final C# wrapper.
43
42
decl . Access = AccessSpecifier . Private ;
44
43
45
- // We need to explicity set the generation else the
44
+ // We need to explicitly set the generation else the
46
45
// now private declaration will get filtered out later.
47
46
decl . GenerationKind = GenerationKind . Generate ;
48
47
}
@@ -51,20 +50,34 @@ static bool ReturnsClassInstance(Function function)
51
50
{
52
51
var returnType = function . ReturnType . Type . Desugar ( ) ;
53
52
54
- var tag = returnType as TagType ;
55
- if ( tag == null )
53
+ if ( returnType is not TagType tag )
56
54
returnType . IsPointerTo ( out tag ) ;
57
55
58
- if ( tag == null )
56
+ var decl = tag ? . Declaration ;
57
+ if ( decl is not Class )
59
58
return false ;
60
59
61
60
var @class = ( Class ) function . Namespace ;
62
- var decl = tag . Declaration ;
61
+ return @class . QualifiedOriginalName == decl . QualifiedOriginalName ;
62
+ }
63
63
64
- if ( ! ( decl is Class ) )
65
- return false ;
64
+ static bool AcceptsClassInstance ( Function function )
65
+ {
66
+ return function . Parameters . Any ( param =>
67
+ {
68
+ var paramType = param . Type . Desugar ( ) ;
66
69
67
- return @class . QualifiedOriginalName == decl . QualifiedOriginalName ;
70
+ if ( paramType is not TagType tag )
71
+ paramType . IsPointerTo ( out tag ) ;
72
+
73
+ var decl = tag ? . Declaration ;
74
+ if ( decl is not Class )
75
+ return false ;
76
+
77
+ var @class = ( Class ) function . Namespace ;
78
+ return @class . QualifiedOriginalName == decl . QualifiedOriginalName ;
79
+ }
80
+ ) ;
68
81
}
69
82
70
83
public override bool VisitClassDecl ( Class @class )
@@ -117,12 +130,10 @@ public override bool VisitClassDecl(Class @class)
117
130
return false ;
118
131
}
119
132
120
- // Check for any static function that return a pointer to the class.
121
- // If one exists, we assume it's a factory function and the class is
122
- // not meant to be static. It's a simple heuristic, but it should be
123
- // good enough for the time being.
124
- if ( @class . Functions . Any ( m => ! m . IsOperator && ReturnsClassInstance ( m ) ) ||
125
- @class . Methods . Any ( m => ! m . IsOperator && ReturnsClassInstance ( m ) ) )
133
+ // Check for any static function that accepts/returns a pointer to the class.
134
+ // If one exists, we assume it's not meant to be static
135
+ if ( @class . Functions . Any ( m => ! m . IsOperator && ( ReturnsClassInstance ( m ) || AcceptsClassInstance ( m ) ) ) ||
136
+ @class . Methods . Any ( m => ! m . IsOperator && ! m . IsConstructor && ( ReturnsClassInstance ( m ) || AcceptsClassInstance ( m ) ) ) )
126
137
return false ;
127
138
128
139
// TODO: We should take C++ friends into account here, they might allow
0 commit comments