9
9
10
10
namespace CppSharp . Generators . Cpp
11
11
{
12
- public class CppMarshalNativeToManagedPrinter : MarshalPrinter < MarshalContext >
12
+ public class CppMarshalNativeToManagedPrinter : MarshalPrinter < MarshalContext , CppTypePrinter >
13
13
{
14
14
public CppMarshalNativeToManagedPrinter ( MarshalContext marshalContext )
15
15
: base ( marshalContext )
@@ -60,17 +60,15 @@ public override bool VisitPointerType(PointerType pointer, TypeQualifiers quals)
60
60
return false ;
61
61
62
62
var pointee = pointer . Pointee . Desugar ( ) ;
63
-
64
- PrimitiveType primitive ;
65
63
var param = Context . Parameter ;
66
64
if ( param != null && ( param . IsOut || param . IsInOut ) &&
67
- pointee . IsPrimitiveType ( out primitive ) )
65
+ pointee . IsPrimitiveType ( ) )
68
66
{
69
67
Context . Return . Write ( Context . ReturnVarName ) ;
70
68
return true ;
71
69
}
72
70
73
- if ( pointee . IsPrimitiveType ( out primitive ) )
71
+ if ( pointee . IsPrimitiveType ( ) )
74
72
{
75
73
var returnVarName = Context . ReturnVarName ;
76
74
@@ -99,8 +97,7 @@ public override bool VisitPointerType(PointerType pointer, TypeQualifiers quals)
99
97
Modifier = pointer . Modifier ,
100
98
QualifiedPointee = new QualifiedType ( pointee )
101
99
} ;
102
- var nativeTypePrinter = new CppTypePrinter ( Context . Context ) ;
103
- var nativeTypeName = desugaredPointer . Visit ( nativeTypePrinter , quals ) ;
100
+ var nativeTypeName = desugaredPointer . Visit ( typePrinter , quals ) ;
104
101
Context . Return . Write ( "reinterpret_cast<{0}>({1})" , nativeTypeName ,
105
102
returnVarName ) ;
106
103
}
@@ -307,9 +304,9 @@ public override bool VisitTypedefDecl(TypedefDecl typedef)
307
304
308
305
public override bool VisitEnumDecl ( Enumeration @enum )
309
306
{
310
- var typePrinter = new CppTypePrinter ( Context . Context ) ;
311
307
typePrinter . PushContext ( TypePrinterContextKind . Managed ) ;
312
308
var typeName = typePrinter . VisitDeclaration ( @enum ) ;
309
+ typePrinter . PopContext ( ) ;
313
310
Context . Return . Write ( $ "({ typeName } ){ Context . ReturnVarName } ") ;
314
311
315
312
return true ;
@@ -331,7 +328,7 @@ public override bool VisitFunctionTemplateDecl(FunctionTemplate template)
331
328
}
332
329
}
333
330
334
- public class CppMarshalManagedToNativePrinter : MarshalPrinter < MarshalContext >
331
+ public class CppMarshalManagedToNativePrinter : MarshalPrinter < MarshalContext , CppTypePrinter >
335
332
{
336
333
public CppMarshalManagedToNativePrinter ( MarshalContext ctx )
337
334
: base ( ctx )
@@ -395,9 +392,9 @@ public override bool VisitPointerType(PointerType pointer, TypeQualifiers quals)
395
392
396
393
if ( pointee is FunctionType )
397
394
{
398
- var cppTypePrinter = new CppTypePrinter ( Context . Context ) ;
399
- cppTypePrinter . PushContext ( TypePrinterContextKind . Managed ) ;
400
- var cppTypeName = pointer . Visit ( cppTypePrinter , quals ) ;
395
+ typePrinter . PushContext ( TypePrinterContextKind . Managed ) ;
396
+ var cppTypeName = pointer . Visit ( typePrinter , quals ) ;
397
+ typePrinter . PopContext ( ) ;
401
398
402
399
return VisitDelegateType ( cppTypeName ) ;
403
400
}
@@ -425,8 +422,7 @@ public override bool VisitPointerType(PointerType pointer, TypeQualifiers quals)
425
422
var finalPointee = pointer . GetFinalPointee ( ) ;
426
423
if ( finalPointee . IsPrimitiveType ( ) )
427
424
{
428
- var cppTypePrinter = new CppTypePrinter ( Context . Context ) ;
429
- var cppTypeName = pointer . Visit ( cppTypePrinter , quals ) ;
425
+ var cppTypeName = pointer . Visit ( typePrinter , quals ) ;
430
426
431
427
Context . Return . Write ( $ "({ cppTypeName } )") ;
432
428
Context . Return . Write ( Context . Parameter . Name ) ;
@@ -489,10 +485,6 @@ public override bool VisitTypedefType(TypedefType typedef, TypeQualifiers quals)
489
485
FunctionType func ;
490
486
if ( decl . Type . IsPointerTo ( out func ) )
491
487
{
492
- var typePrinter = new CppTypePrinter ( Context . Context ) ;
493
- typePrinter . PushContext ( TypePrinterContextKind . Native ) ;
494
- var declName = decl . Visit ( typePrinter ) ;
495
- typePrinter . PopContext ( ) ;
496
488
// Use the original typedef name if available, otherwise just use the function pointer type
497
489
string cppTypeName ;
498
490
if ( ! decl . IsSynthetized )
0 commit comments