@@ -10,17 +10,24 @@ namespace CppSharp.Passes
10
10
/// </summary>
11
11
public class CheckOperatorsOverloadsPass : TranslationUnitPass
12
12
{
13
- public CheckOperatorsOverloadsPass ( )
14
- {
15
- ClearVisitedDeclarations = false ;
16
- }
13
+ public CheckOperatorsOverloadsPass ( ) =>
14
+ VisitOptions . VisitClassBases =
15
+ VisitOptions . VisitClassFields =
16
+ VisitOptions . VisitEventParameters =
17
+ VisitOptions . VisitFunctionParameters =
18
+ VisitOptions . VisitFunctionReturnType =
19
+ VisitOptions . VisitClassMethods =
20
+ VisitOptions . VisitNamespaceEnums =
21
+ VisitOptions . VisitNamespaceEvents =
22
+ VisitOptions . VisitNamespaceTemplates =
23
+ VisitOptions . VisitNamespaceTypedefs =
24
+ VisitOptions . VisitNamespaceVariables =
25
+ VisitOptions . VisitPropertyAccessors =
26
+ VisitOptions . VisitTemplateArguments = false ;
17
27
18
28
public override bool VisitClassDecl ( Class @class )
19
29
{
20
- if ( @class . CompleteDeclaration != null )
21
- return VisitClassDecl ( @class . CompleteDeclaration as Class ) ;
22
-
23
- if ( ! VisitDeclarationContext ( @class ) )
30
+ if ( ! base . VisitClassDecl ( @class ) )
24
31
return false ;
25
32
26
33
// Check for C++ operators that cannot be represented in .NET.
@@ -49,14 +56,6 @@ private void CheckInvalidOperators(Class @class)
49
56
{
50
57
foreach ( var @operator in @class . Operators . Where ( o => o . IsGenerated ) )
51
58
{
52
- if ( ! IsValidOperatorOverload ( @operator ) || @operator . IsPure )
53
- {
54
- Diagnostics . Debug ( "Invalid operator overload {0}::{1}" ,
55
- @class . OriginalName , @operator . OperatorKind ) ;
56
- @operator . ExplicitlyIgnore ( ) ;
57
- continue ;
58
- }
59
-
60
59
if ( @operator . IsNonMemberOperator )
61
60
continue ;
62
61
@@ -184,118 +183,5 @@ static CXXOperatorKind CheckMissingOperatorOverloadPair(Class @class, out int in
184
183
index = 0 ;
185
184
return CXXOperatorKind . None ;
186
185
}
187
-
188
- private bool IsValidOperatorOverload ( Method @operator )
189
- {
190
- // These follow the order described in MSDN (Overloadable Operators).
191
-
192
- switch ( @operator . OperatorKind )
193
- {
194
- // These unary operators can be overloaded
195
- case CXXOperatorKind . Plus :
196
- case CXXOperatorKind . Minus :
197
- case CXXOperatorKind . Exclaim :
198
- case CXXOperatorKind . Tilde :
199
-
200
- // These binary operators can be overloaded
201
- case CXXOperatorKind . Slash :
202
- case CXXOperatorKind . Percent :
203
- case CXXOperatorKind . Amp :
204
- case CXXOperatorKind . Pipe :
205
- case CXXOperatorKind . Caret :
206
-
207
- // The array indexing operator can be overloaded
208
- case CXXOperatorKind . Subscript :
209
-
210
- // The conversion operators can be overloaded
211
- case CXXOperatorKind . Conversion :
212
- case CXXOperatorKind . ExplicitConversion :
213
- return true ;
214
-
215
- // The comparison operators can be overloaded if their return type is bool
216
- case CXXOperatorKind . EqualEqual :
217
- case CXXOperatorKind . ExclaimEqual :
218
- case CXXOperatorKind . Less :
219
- case CXXOperatorKind . Greater :
220
- case CXXOperatorKind . LessEqual :
221
- case CXXOperatorKind . GreaterEqual :
222
- return @operator . ReturnType . Type . IsPrimitiveType ( PrimitiveType . Bool ) ;
223
-
224
- // Only prefix operators can be overloaded
225
- case CXXOperatorKind . PlusPlus :
226
- case CXXOperatorKind . MinusMinus :
227
- Class @class ;
228
- var returnType = @operator . OriginalReturnType . Type . Desugar ( ) ;
229
- returnType = ( returnType . GetFinalPointee ( ) ?? returnType ) . Desugar ( ) ;
230
- return returnType . TryGetClass ( out @class ) &&
231
- @class . GetNonIgnoredRootBase ( ) ==
232
- ( ( Class ) @operator . Namespace ) . GetNonIgnoredRootBase ( ) &&
233
- @operator . Parameters . Count == 0 ;
234
-
235
- // Bitwise shift operators can only be overloaded if the second parameter is int
236
- case CXXOperatorKind . LessLess :
237
- case CXXOperatorKind . GreaterGreater :
238
- {
239
- Parameter parameter = @operator . Parameters . Last ( ) ;
240
- Type type = parameter . Type . Desugar ( ) ;
241
- switch ( Options . GeneratorKind )
242
- {
243
- case GeneratorKind . CLI :
244
- return type . IsPrimitiveType ( PrimitiveType . Int ) ;
245
- case GeneratorKind . CSharp :
246
- Types . TypeMap typeMap ;
247
- if ( Context . TypeMaps . FindTypeMap ( type , out typeMap ) )
248
- {
249
- var mappedTo = typeMap . CSharpSignatureType (
250
- new TypePrinterContext
251
- {
252
- Parameter = parameter ,
253
- Type = type
254
- } ) ;
255
- var cilType = mappedTo as CILType ;
256
- if ( cilType ? . Type == typeof ( int ) )
257
- return true ;
258
- }
259
- break ;
260
- }
261
- return false ;
262
- }
263
-
264
- // No parameters means the dereference operator - cannot be overloaded
265
- case CXXOperatorKind . Star :
266
- return @operator . Parameters . Count > 0 ;
267
-
268
- // Assignment operators cannot be overloaded
269
- case CXXOperatorKind . PlusEqual :
270
- case CXXOperatorKind . MinusEqual :
271
- case CXXOperatorKind . StarEqual :
272
- case CXXOperatorKind . SlashEqual :
273
- case CXXOperatorKind . PercentEqual :
274
- case CXXOperatorKind . AmpEqual :
275
- case CXXOperatorKind . PipeEqual :
276
- case CXXOperatorKind . CaretEqual :
277
- case CXXOperatorKind . LessLessEqual :
278
- case CXXOperatorKind . GreaterGreaterEqual :
279
-
280
- // The conditional logical operators cannot be overloaded
281
- case CXXOperatorKind . AmpAmp :
282
- case CXXOperatorKind . PipePipe :
283
-
284
- // These operators cannot be overloaded.
285
- case CXXOperatorKind . Equal :
286
- case CXXOperatorKind . Comma :
287
- case CXXOperatorKind . ArrowStar :
288
- case CXXOperatorKind . Arrow :
289
- case CXXOperatorKind . Call :
290
- case CXXOperatorKind . Conditional :
291
- case CXXOperatorKind . Coawait :
292
- case CXXOperatorKind . New :
293
- case CXXOperatorKind . Delete :
294
- case CXXOperatorKind . Array_New :
295
- case CXXOperatorKind . Array_Delete :
296
- default :
297
- return false ;
298
- }
299
- }
300
186
}
301
187
}
0 commit comments