1
1
using Biohazrd . CSharp . Trampolines ;
2
2
using Biohazrd . Transformation ;
3
3
using ClangSharp . Pathogen ;
4
- using System ;
5
4
using System . Collections . Generic ;
6
5
using System . Collections . Immutable ;
7
6
using System . Diagnostics ;
@@ -62,13 +61,20 @@ void AddFriendlyAdapter(Adapter target, Adapter adapter)
62
61
TypeReference returnType = declaration . ReturnType ;
63
62
64
63
// Handle returning bool
65
- if ( TargetRuntime < TargetRuntime . Net7 && returnType == CSharpBuiltinType . Bool )
64
+ if ( TargetRuntime < TargetRuntime . Net7 && returnType . IsCSharpType ( context . Library , CSharpBuiltinType . Bool ) )
66
65
{
67
- //TODO: If function is virtual method rewrite to NativeBoolean instead.
68
- nativeReturnAdapter = new PassthroughReturnAdapter ( CSharpBuiltinType . Byte ) ;
69
- friendlyReturnAdapter = new ByteToBoolReturnAdapter ( nativeReturnAdapter ) ;
66
+ // If the function is virtual, use NativeBoolean on the native side and allow the friendly side to just be passthrough
67
+ if ( declaration . IsVirtual )
68
+ { nativeReturnAdapter = NonBlittableTypeReturnAdapter . NativeBoolean ; }
69
+ else
70
+ {
71
+ nativeReturnAdapter = new PassthroughReturnAdapter ( CSharpBuiltinType . Byte ) ;
72
+ friendlyReturnAdapter = new ByteToBoolReturnAdapter ( nativeReturnAdapter ) ;
73
+ }
70
74
}
71
- //TODO: Handle char for virtual methods
75
+ // Handle virtual methods returning bool
76
+ else if ( declaration . IsVirtual && TargetRuntime < TargetRuntime . Net7 && returnType . IsCSharpType ( context . Library , CSharpBuiltinType . Char ) )
77
+ { nativeReturnAdapter = NonBlittableTypeReturnAdapter . NativeChar ; }
72
78
// Handle returning void
73
79
else if ( returnType is VoidTypeReference )
74
80
{ nativeReturnAdapter = VoidReturnAdapter . Instance ; }
@@ -129,26 +135,6 @@ void CreateNativeReturnByReferenceAdapter()
129
135
// Handle explicit parameters
130
136
foreach ( TranslatedParameter parameter in declaration . Parameters )
131
137
{
132
- // Handle pre-.NET 7 non-blittables
133
- if ( TargetRuntime < TargetRuntime . Net7 )
134
- {
135
- // Handle bool
136
- if ( parameter . Type == CSharpBuiltinType . Bool )
137
- {
138
- //TODO: Rewrite to NativeBoolean for virtual methods
139
- Adapter nativeAdapter = new PassthroughAdapter ( parameter , CSharpBuiltinType . Byte ) ;
140
- nativeAdapters . Add ( nativeAdapter ) ;
141
- AddFriendlyAdapter ( nativeAdapter , new BoolToByteAdapter ( nativeAdapter ) ) ;
142
- continue ;
143
- }
144
-
145
- // Handle char
146
- if ( declaration . IsVirtual && parameter . Type == CSharpBuiltinType . Char )
147
- {
148
- //TODO: Rewrite to NativeChar for virtual methods
149
- }
150
- }
151
-
152
138
// Handle implicit pass by reference
153
139
if ( parameter . ImplicitlyPassedByReference )
154
140
{
@@ -164,6 +150,32 @@ void CreateNativeReturnByReferenceAdapter()
164
150
continue ;
165
151
}
166
152
153
+ // Handle pre-.NET 7 non-blittables
154
+ if ( TargetRuntime < TargetRuntime . Net7 )
155
+ {
156
+ // Handle bool
157
+ if ( parameter . Type . IsCSharpType ( context . Library , CSharpBuiltinType . Bool ) )
158
+ {
159
+ // If the function is virtual, use NativeBoolean on the native side and allow the friendly side to just be passthrough
160
+ if ( declaration . IsVirtual )
161
+ { nativeAdapters . Add ( new NonBlittableTypeAdapter ( parameter , NonBlittableTypeKind . NativeBoolean ) ) ; }
162
+ else
163
+ {
164
+ Adapter nativeAdapter = new PassthroughAdapter ( parameter , CSharpBuiltinType . Byte ) ;
165
+ nativeAdapters . Add ( nativeAdapter ) ;
166
+ AddFriendlyAdapter ( nativeAdapter , new BoolToByteAdapter ( nativeAdapter ) ) ;
167
+ }
168
+ continue ;
169
+ }
170
+
171
+ // Handle char -- No friendly adapter needed, it can just be passthrough
172
+ if ( declaration . IsVirtual && parameter . Type . IsCSharpType ( context . Library , CSharpBuiltinType . Char ) )
173
+ {
174
+ nativeAdapters . Add ( new NonBlittableTypeAdapter ( parameter , NonBlittableTypeKind . NativeChar ) ) ;
175
+ continue ;
176
+ }
177
+ }
178
+
167
179
// Typical case
168
180
{
169
181
Adapter nativeAdapter = new PassthroughAdapter ( parameter ) ;
0 commit comments