@@ -184,8 +184,9 @@ private void GenerateClassConstructors(Class @class)
184
184
if ( @class . IsStatic )
185
185
return ;
186
186
187
- // Output a default constructor that takes the native pointer.
187
+ // Output the default constructors taking the native pointer and ownership info .
188
188
GenerateClassConstructor ( @class ) ;
189
+ GenerateClassConstructor ( @class , true ) ;
189
190
190
191
if ( @class . IsRefType )
191
192
{
@@ -630,7 +631,7 @@ private void GenerateClassConstructor(Class @class, bool withOwnNativeInstancePa
630
631
Write ( "{0}::{1}(" , qualifiedIdentifier , @class . Name ) ;
631
632
632
633
var nativeType = string . Format ( "::{0}*" , @class . QualifiedOriginalName ) ;
633
- WriteLine ( ! withOwnNativeInstanceParam ? "{0} native)" : "{0} native, const bool ownNativeInstance)" , nativeType ) ;
634
+ WriteLine ( ! withOwnNativeInstanceParam ? "{0} native)" : "{0} native, bool ownNativeInstance)" , nativeType ) ;
634
635
635
636
var hasBase = GenerateClassConstructorBase ( @class , null , withOwnNativeInstanceParam ) ;
636
637
@@ -677,11 +678,6 @@ private void GenerateClassConstructor(Class @class, bool withOwnNativeInstancePa
677
678
678
679
UnindentAndWriteCloseBrace ( ) ;
679
680
NewLine ( ) ;
680
-
681
- if ( ! withOwnNativeInstanceParam )
682
- {
683
- GenerateClassConstructor ( @class , true ) ;
684
- }
685
681
}
686
682
687
683
private void GenerateStructMarshaling ( Class @class , string nativeVar )
@@ -719,29 +715,29 @@ private void GenerateStructMarshaling(Class @class, string nativeVar)
719
715
}
720
716
}
721
717
722
- private bool GenerateClassConstructorBase ( Class @class , Method method = null , bool withOwnNativeInstanceParam = false )
718
+ private bool GenerateClassConstructorBase ( Class @class , Method method = null ,
719
+ bool withOwnNativeInstanceParam = false )
723
720
{
724
- var hasBase = @class . HasBase && @class . Bases [ 0 ] . IsClass && @class . Bases [ 0 ] . Class . IsGenerated ;
725
- if ( ! hasBase )
721
+ if ( ! @class . NeedsBase )
726
722
return false ;
727
723
728
- if ( ! @class . IsValueType )
729
- {
730
- Indent ( ) ;
724
+ if ( @class . IsValueType )
725
+ return true ;
731
726
732
- var baseClass = @class . Bases [ 0 ] . Class ;
733
- Write ( ": {0}(" , QualifiedIdentifier ( baseClass ) ) ;
727
+ Indent ( ) ;
734
728
735
- // We cast the value to the base clas type since otherwise there
736
- // could be ambiguous call to overloaded constructors.
737
- var cppTypePrinter = new CppTypePrinter ( Context ) ;
738
- var nativeTypeName = baseClass . Visit ( cppTypePrinter ) ;
739
- Write ( "({0}*)" , nativeTypeName ) ;
729
+ Write ( $ ": { QualifiedIdentifier ( @class . BaseClass ) } (") ;
740
730
741
- WriteLine ( "{0}{1})" , method != null ? "nullptr" : "native" , ! withOwnNativeInstanceParam ? "" : ", ownNativeInstance" ) ;
731
+ // We cast the value to the base class type since otherwise there
732
+ // could be ambiguous call to overloaded constructors.
733
+ var cppTypePrinter = new CppTypePrinter ( Context ) ;
734
+ var nativeTypeName = @class . BaseClass . Visit ( cppTypePrinter ) ;
742
735
743
- Unindent ( ) ;
744
- }
736
+ Write ( $ "({ nativeTypeName } *)") ;
737
+ WriteLine ( "{0}{1})" , method != null ? "nullptr" : "native" ,
738
+ ! withOwnNativeInstanceParam ? "" : ", ownNativeInstance" ) ;
739
+
740
+ Unindent ( ) ;
745
741
746
742
return true ;
747
743
}
0 commit comments