99
1010namespace CppSharp . Generators . Cpp
1111{
12- public class CppMarshalNativeToManagedPrinter : MarshalPrinter < MarshalContext >
12+ public class CppMarshalNativeToManagedPrinter : MarshalPrinter < MarshalContext , CppTypePrinter >
1313 {
1414 public CppMarshalNativeToManagedPrinter ( MarshalContext marshalContext )
1515 : base ( marshalContext )
@@ -60,17 +60,15 @@ public override bool VisitPointerType(PointerType pointer, TypeQualifiers quals)
6060 return false ;
6161
6262 var pointee = pointer . Pointee . Desugar ( ) ;
63-
64- PrimitiveType primitive ;
6563 var param = Context . Parameter ;
6664 if ( param != null && ( param . IsOut || param . IsInOut ) &&
67- pointee . IsPrimitiveType ( out primitive ) )
65+ pointee . IsPrimitiveType ( ) )
6866 {
6967 Context . Return . Write ( Context . ReturnVarName ) ;
7068 return true ;
7169 }
7270
73- if ( pointee . IsPrimitiveType ( out primitive ) )
71+ if ( pointee . IsPrimitiveType ( ) )
7472 {
7573 var returnVarName = Context . ReturnVarName ;
7674
@@ -99,8 +97,7 @@ public override bool VisitPointerType(PointerType pointer, TypeQualifiers quals)
9997 Modifier = pointer . Modifier ,
10098 QualifiedPointee = new QualifiedType ( pointee )
10199 } ;
102- var nativeTypePrinter = new CppTypePrinter ( Context . Context ) ;
103- var nativeTypeName = desugaredPointer . Visit ( nativeTypePrinter , quals ) ;
100+ var nativeTypeName = desugaredPointer . Visit ( typePrinter , quals ) ;
104101 Context . Return . Write ( "reinterpret_cast<{0}>({1})" , nativeTypeName ,
105102 returnVarName ) ;
106103 }
@@ -307,9 +304,9 @@ public override bool VisitTypedefDecl(TypedefDecl typedef)
307304
308305 public override bool VisitEnumDecl ( Enumeration @enum )
309306 {
310- var typePrinter = new CppTypePrinter ( Context . Context ) ;
311307 typePrinter . PushContext ( TypePrinterContextKind . Managed ) ;
312308 var typeName = typePrinter . VisitDeclaration ( @enum ) ;
309+ typePrinter . PopContext ( ) ;
313310 Context . Return . Write ( $ "({ typeName } ){ Context . ReturnVarName } ") ;
314311
315312 return true ;
@@ -331,7 +328,7 @@ public override bool VisitFunctionTemplateDecl(FunctionTemplate template)
331328 }
332329 }
333330
334- public class CppMarshalManagedToNativePrinter : MarshalPrinter < MarshalContext >
331+ public class CppMarshalManagedToNativePrinter : MarshalPrinter < MarshalContext , CppTypePrinter >
335332 {
336333 public CppMarshalManagedToNativePrinter ( MarshalContext ctx )
337334 : base ( ctx )
@@ -395,9 +392,9 @@ public override bool VisitPointerType(PointerType pointer, TypeQualifiers quals)
395392
396393 if ( pointee is FunctionType )
397394 {
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 ( ) ;
401398
402399 return VisitDelegateType ( cppTypeName ) ;
403400 }
@@ -425,8 +422,7 @@ public override bool VisitPointerType(PointerType pointer, TypeQualifiers quals)
425422 var finalPointee = pointer . GetFinalPointee ( ) ;
426423 if ( finalPointee . IsPrimitiveType ( ) )
427424 {
428- var cppTypePrinter = new CppTypePrinter ( Context . Context ) ;
429- var cppTypeName = pointer . Visit ( cppTypePrinter , quals ) ;
425+ var cppTypeName = pointer . Visit ( typePrinter , quals ) ;
430426
431427 Context . Return . Write ( $ "({ cppTypeName } )") ;
432428 Context . Return . Write ( Context . Parameter . Name ) ;
@@ -489,10 +485,6 @@ public override bool VisitTypedefType(TypedefType typedef, TypeQualifiers quals)
489485 FunctionType func ;
490486 if ( decl . Type . IsPointerTo ( out func ) )
491487 {
492- var typePrinter = new CppTypePrinter ( Context . Context ) ;
493- typePrinter . PushContext ( TypePrinterContextKind . Native ) ;
494- var declName = decl . Visit ( typePrinter ) ;
495- typePrinter . PopContext ( ) ;
496488 // Use the original typedef name if available, otherwise just use the function pointer type
497489 string cppTypeName ;
498490 if ( ! decl . IsSynthetized )
0 commit comments