@@ -162,7 +162,7 @@ public virtual void GenerateClassConstructors(Class @class)
162
162
return ;
163
163
164
164
// Output a default constructor that takes the native instance.
165
- GenerateClassConstructor ( @class ) ;
165
+ GenerateClassConstructor ( @class , withOwnNativeInstanceParam : true ) ;
166
166
167
167
if ( @class . IsRefType )
168
168
{
@@ -290,15 +290,26 @@ public override bool VisitVariableDecl(Variable variable)
290
290
return true ;
291
291
}
292
292
293
- public virtual string ClassCtorInstanceParamIdentifier => "instance" ;
294
-
295
- public virtual void GenerateClassConstructor ( Class @class )
293
+ public virtual void GenerateClassConstructor ( Class @class , bool withOwnNativeInstanceParam = false )
296
294
{
297
295
Write ( $ "{ QualifiedIdentifier ( @class ) } ::{ @class . Name } (") ;
298
296
299
297
var nativeType = $ "::{ @class . QualifiedOriginalName } *";
300
- WriteLine ( $ "{ nativeType } { ClassCtorInstanceParamIdentifier } )") ;
301
- GenerateClassConstructorBase ( @class ) ;
298
+ //WriteLine($"{nativeType} {ClassCtorInstanceParamIdentifier})");
299
+ WriteLine ( ! withOwnNativeInstanceParam ? $ "{ nativeType } { ClassCtorInstanceParamIdentifier } )" :
300
+ $ "{ nativeType } { ClassCtorInstanceParamIdentifier } , bool ownNativeInstance)") ;
301
+
302
+ var hasBase = GenerateClassConstructorBase ( @class , null , withOwnNativeInstanceParam ) ;
303
+
304
+ if ( CLIGenerator . ShouldGenerateClassNativeField ( @class ) )
305
+ {
306
+ Indent ( ) ;
307
+ Write ( hasBase ? "," : ":" ) ;
308
+ Unindent ( ) ;
309
+
310
+ WriteLine ( ! withOwnNativeInstanceParam ? " {0}(false)" : " {0}(ownNativeInstance)" ,
311
+ Helpers . OwnsNativeInstanceIdentifier ) ;
312
+ }
302
313
303
314
WriteOpenBraceAndIndent ( ) ;
304
315
@@ -312,30 +323,29 @@ public virtual void GenerateClassConstructor(Class @class)
312
323
NewLine ( ) ;
313
324
}
314
325
315
- private bool GenerateClassConstructorBase ( Class @class , Method method = null )
326
+ private bool GenerateClassConstructorBase ( Class @class , Method method = null ,
327
+ bool withOwnNativeInstanceParam = false )
316
328
{
317
- var hasBase = @class . HasBase && @class . Bases [ 0 ] . IsClass && @class . Bases [ 0 ] . Class . IsGenerated ;
318
- if ( ! hasBase )
329
+ if ( @class . IsValueType )
330
+ return true ;
331
+
332
+ if ( ! @class . NeedsBase )
319
333
return false ;
320
334
321
- if ( ! @class . IsValueType )
322
- {
323
- Indent ( ) ;
335
+ Indent ( ) ;
324
336
325
- var baseClass = @class . Bases [ 0 ] . Class ;
326
- Write ( $ ": { QualifiedIdentifier ( baseClass ) } (") ;
337
+ Write ( $ ": { QualifiedIdentifier ( @class . BaseClass ) } (") ;
327
338
328
- // We cast the value to the base class type since otherwise there
329
- // could be ambiguous call to overloaded constructors.
330
- CTypePrinter . PushContext ( TypePrinterContextKind . Native ) ;
331
- var nativeTypeName = baseClass . Visit ( CTypePrinter ) ;
332
- CTypePrinter . PopContext ( ) ;
333
- Write ( $ "({ nativeTypeName } *)") ;
339
+ // We cast the value to the base class type since otherwise there
340
+ // could be ambiguous call to overloaded constructors.
341
+ var cppTypePrinter = new CppTypePrinter ( Context ) ;
342
+ var nativeTypeName = @class . BaseClass . Visit ( cppTypePrinter ) ;
334
343
335
- WriteLine ( "{0})" , method != null ? "nullptr" : ClassCtorInstanceParamIdentifier ) ;
344
+ Write ( $ "({ nativeTypeName } *)") ;
345
+ WriteLine ( "{0}{1})" , method != null ? "nullptr" : ClassCtorInstanceParamIdentifier ,
346
+ ! withOwnNativeInstanceParam ? "" : ", ownNativeInstance" ) ;
336
347
337
- Unindent ( ) ;
338
- }
348
+ Unindent ( ) ;
339
349
340
350
return true ;
341
351
}
0 commit comments