Browse Source

Add experimental GenerateExternalDataFields option and supporting code.

pull/1581/head
Joao Matos 4 years ago committed by João Matos
parent
commit
f0becc879c
  1. 41
      src/Generator/Generators/C/CppHeaders.cs
  2. 6
      src/Generator/Options.cs

41
src/Generator/Generators/C/CppHeaders.cs

@ -329,6 +329,9 @@ namespace CppSharp.Generators.Cpp @@ -329,6 +329,9 @@ namespace CppSharp.Generators.Cpp
if (CppGenerator.ShouldGenerateClassNativeInstanceField(@class))
GenerateClassNativeField(@class);
if (Options.GenerateExternalDataFields)
GenerateExternalDataFields(@class);
GenerateClassConstructors(@class);
GenerateClassProperties(@class);
GenerateClassEvents(@class);
@ -366,6 +369,44 @@ namespace CppSharp.Generators.Cpp @@ -366,6 +369,44 @@ namespace CppSharp.Generators.Cpp
return true;
}
// Generate an external instance storage location for external bindings.
public virtual void GenerateExternalDataFields(Class @class)
{
PushBlock();
var voidPtrType = new PointerType(new QualifiedType(new BuiltinType(PrimitiveType.Void)));
var externalInstanceField = new Field()
{
Name = Generator.GeneratedIdentifier("ExternalInstance"),
QualifiedType = new QualifiedType(voidPtrType),
Namespace = @class
};
Indent();
CTypePrinter.PushContext(TypePrinterContextKind.Native);
externalInstanceField.Visit(this);
CTypePrinter.PopContext();
var externalDataField = new Field()
{
Name = Generator.GeneratedIdentifier("ExternalData"),
QualifiedType = new QualifiedType(new ArrayType
{
QualifiedType = new QualifiedType(voidPtrType),
SizeType = ArrayType.ArraySize.Constant,
Size = 2
}),
Namespace = @class
};
CTypePrinter.PushContext(TypePrinterContextKind.Native);
var result = externalDataField.Visit(CTypePrinter);
CTypePrinter.PopContext();
Unindent();
PopBlock(NewLineKind.BeforeNextBlock);
}
public void GenerateClassNativeField(Class @class)
{
PushBlock();

6
src/Generator/Options.cs

@ -185,6 +185,12 @@ namespace CppSharp @@ -185,6 +185,12 @@ namespace CppSharp
public bool UsePropertyDetectionHeuristics { get; set; } = true;
/// <summary>
/// Experimental option that makes the C/C++ generator generate some extra data storage
/// on the generated instance, for supporting higher-level binding of the code.
/// </summary>
public bool GenerateExternalDataFields { get; set; } = false;
#endregion
}

Loading…
Cancel
Save