|
|
@ -52,8 +52,8 @@ namespace CppSharp.Generators.CLI |
|
|
|
|
|
|
|
|
|
|
|
public void GenerateIncludeForwardRefs() |
|
|
|
public void GenerateIncludeForwardRefs() |
|
|
|
{ |
|
|
|
{ |
|
|
|
var typeReferenceCollector = new CLITypeReferenceCollector(Driver.TypeDatabase, |
|
|
|
var typeReferenceCollector = new CLITypeReferenceCollector(Driver.TypeDatabase, |
|
|
|
Driver.Options); |
|
|
|
Driver.Options); |
|
|
|
typeReferenceCollector.Process(TranslationUnit, filterNamespaces: false); |
|
|
|
typeReferenceCollector.Process(TranslationUnit, filterNamespaces: false); |
|
|
|
|
|
|
|
|
|
|
|
var includes = new SortedSet<string>(StringComparer.InvariantCulture); |
|
|
|
var includes = new SortedSet<string>(StringComparer.InvariantCulture); |
|
|
@ -68,8 +68,8 @@ namespace CppSharp.Generators.CLI |
|
|
|
|
|
|
|
|
|
|
|
var include = typeRef.Include; |
|
|
|
var include = typeRef.Include; |
|
|
|
var unit = include.TranslationUnit; |
|
|
|
var unit = include.TranslationUnit; |
|
|
|
|
|
|
|
|
|
|
|
if (unit != null && !unit.IsDeclared) |
|
|
|
if (unit != null && !unit.IsDeclared) |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
|
|
if(!string.IsNullOrEmpty(include.File) && include.InHeader) |
|
|
|
if(!string.IsNullOrEmpty(include.File) && include.InHeader) |
|
|
@ -130,8 +130,8 @@ namespace CppSharp.Generators.CLI |
|
|
|
|
|
|
|
|
|
|
|
public void GenerateForwardRefs() |
|
|
|
public void GenerateForwardRefs() |
|
|
|
{ |
|
|
|
{ |
|
|
|
var typeReferenceCollector = new CLITypeReferenceCollector(Driver.TypeDatabase, |
|
|
|
var typeReferenceCollector = new CLITypeReferenceCollector(Driver.TypeDatabase, |
|
|
|
Driver.Options); |
|
|
|
Driver.Options); |
|
|
|
typeReferenceCollector.Process(TranslationUnit); |
|
|
|
typeReferenceCollector.Process(TranslationUnit); |
|
|
|
|
|
|
|
|
|
|
|
var typeReferences = typeReferenceCollector.TypeReferences; |
|
|
|
var typeReferences = typeReferenceCollector.TypeReferences; |
|
|
@ -151,7 +151,7 @@ namespace CppSharp.Generators.CLI |
|
|
|
// Generate all the enum declarations for the module.
|
|
|
|
// Generate all the enum declarations for the module.
|
|
|
|
foreach (var @enum in decl.Enums) |
|
|
|
foreach (var @enum in decl.Enums) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!@enum.IsGenerated || @enum.IsIncomplete) |
|
|
|
if (!@enum.IsGenerated || @enum.IsIncomplete) |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
|
|
PushBlock(CLIBlockKind.Enum, @enum); |
|
|
|
PushBlock(CLIBlockKind.Enum, @enum); |
|
|
@ -165,7 +165,7 @@ namespace CppSharp.Generators.CLI |
|
|
|
// Generate all the struct/class declarations for the module.
|
|
|
|
// Generate all the struct/class declarations for the module.
|
|
|
|
foreach (var @class in decl.Classes) |
|
|
|
foreach (var @class in decl.Classes) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!@class.IsGenerated || @class.IsIncomplete) |
|
|
|
if (!@class.IsGenerated || @class.IsIncomplete) |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
|
|
if (@class.IsOpaque) |
|
|
|
if (@class.IsOpaque) |
|
|
@ -210,7 +210,7 @@ namespace CppSharp.Generators.CLI |
|
|
|
{ |
|
|
|
{ |
|
|
|
foreach (var typedef in decl.Typedefs) |
|
|
|
foreach (var typedef in decl.Typedefs) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!typedef.IsGenerated) |
|
|
|
if (!typedef.IsGenerated) |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
|
|
GenerateTypedef(typedef); |
|
|
|
GenerateTypedef(typedef); |
|
|
@ -221,7 +221,7 @@ namespace CppSharp.Generators.CLI |
|
|
|
{ |
|
|
|
{ |
|
|
|
PushBlock(CLIBlockKind.FunctionsClass); |
|
|
|
PushBlock(CLIBlockKind.FunctionsClass); |
|
|
|
|
|
|
|
|
|
|
|
WriteLine("public ref class {0}", TranslationUnit.FileNameWithoutExtension); |
|
|
|
WriteLine("public ref class {0}", TranslationUnit.FileNameWithoutExtension); |
|
|
|
WriteLine("{"); |
|
|
|
WriteLine("{"); |
|
|
|
WriteLine("public:"); |
|
|
|
WriteLine("public:"); |
|
|
|
PushIndent(); |
|
|
|
PushIndent(); |
|
|
@ -240,7 +240,7 @@ namespace CppSharp.Generators.CLI |
|
|
|
|
|
|
|
|
|
|
|
public void GenerateClass(Class @class) |
|
|
|
public void GenerateClass(Class @class) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!@class.IsGenerated || @class.IsIncomplete) |
|
|
|
if (!@class.IsGenerated || @class.IsIncomplete) |
|
|
|
return; |
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
GenerateDeclarationCommon(@class); |
|
|
|
GenerateDeclarationCommon(@class); |
|
|
@ -270,15 +270,15 @@ namespace CppSharp.Generators.CLI |
|
|
|
|
|
|
|
|
|
|
|
GenerateClassVariables(@class); |
|
|
|
GenerateClassVariables(@class); |
|
|
|
|
|
|
|
|
|
|
|
PushBlock(CLIBlockKind.AccessSpecifier); |
|
|
|
PushBlock(CLIBlockKind.AccessSpecifier); |
|
|
|
WriteLine("private:"); |
|
|
|
WriteLine("private:"); |
|
|
|
var accBlock = PopBlock(NewLineKind.IfNotEmpty); |
|
|
|
var accBlock = PopBlock(NewLineKind.IfNotEmpty); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PushBlock(CLIBlockKind.Fields); |
|
|
|
|
|
|
|
GenerateClassFields(@class); |
|
|
|
|
|
|
|
var fieldsBlock = PopBlock(); |
|
|
|
|
|
|
|
|
|
|
|
PushBlock(CLIBlockKind.Fields); |
|
|
|
accBlock.CheckGenerate = () => !fieldsBlock.IsEmpty; |
|
|
|
GenerateClassFields(@class); |
|
|
|
|
|
|
|
var fieldsBlock = PopBlock(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
accBlock.CheckGenerate = () => !fieldsBlock.IsEmpty; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
WriteLine("};"); |
|
|
|
WriteLine("};"); |
|
|
|
} |
|
|
|
} |
|
|
@ -306,7 +306,7 @@ namespace CppSharp.Generators.CLI |
|
|
|
PushIndent(); |
|
|
|
PushIndent(); |
|
|
|
foreach (var template in @class.Templates) |
|
|
|
foreach (var template in @class.Templates) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!template.IsGenerated) continue; |
|
|
|
if (!template.IsGenerated) continue; |
|
|
|
|
|
|
|
|
|
|
|
var functionTemplate = template as FunctionTemplate; |
|
|
|
var functionTemplate = template as FunctionTemplate; |
|
|
|
if (functionTemplate == null) continue; |
|
|
|
if (functionTemplate == null) continue; |
|
|
@ -371,7 +371,7 @@ namespace CppSharp.Generators.CLI |
|
|
|
WriteLine("{0}({1} native);", @class.Name, "System::IntPtr"); |
|
|
|
WriteLine("{0}({1} native);", @class.Name, "System::IntPtr"); |
|
|
|
|
|
|
|
|
|
|
|
foreach (var ctor in @class.Constructors) |
|
|
|
foreach (var ctor in @class.Constructors) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (ASTUtils.CheckIgnoreMethod(ctor, Options)) |
|
|
|
if (ASTUtils.CheckIgnoreMethod(ctor, Options)) |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
|
@ -382,10 +382,15 @@ namespace CppSharp.Generators.CLI |
|
|
|
GenerateMethod(ctor); |
|
|
|
GenerateMethod(ctor); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (@class.IsRefType) |
|
|
|
if (Options.GenerateFinalizers && @class.IsRefType) |
|
|
|
{ |
|
|
|
{ |
|
|
|
GenerateClassDestructor(@class); |
|
|
|
var destructor = @class.Destructors |
|
|
|
GenerateClassFinalizer(@class); |
|
|
|
.FirstOrDefault(d => d.Parameters.Count == 0 && d.Access == AccessSpecifier.Public); |
|
|
|
|
|
|
|
if (destructor != null) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
GenerateClassDestructor(@class); |
|
|
|
|
|
|
|
GenerateClassFinalizer(@class); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
PopIndent(); |
|
|
|
PopIndent(); |
|
|
@ -393,9 +398,6 @@ namespace CppSharp.Generators.CLI |
|
|
|
|
|
|
|
|
|
|
|
private void GenerateClassDestructor(Class @class) |
|
|
|
private void GenerateClassDestructor(Class @class) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!Options.GenerateFinalizers) |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PushBlock(CLIBlockKind.Destructor); |
|
|
|
PushBlock(CLIBlockKind.Destructor); |
|
|
|
WriteLine("~{0}();", @class.Name); |
|
|
|
WriteLine("~{0}();", @class.Name); |
|
|
|
PopBlock(NewLineKind.BeforeNextBlock); |
|
|
|
PopBlock(NewLineKind.BeforeNextBlock); |
|
|
@ -403,9 +405,6 @@ namespace CppSharp.Generators.CLI |
|
|
|
|
|
|
|
|
|
|
|
private void GenerateClassFinalizer(Class @class) |
|
|
|
private void GenerateClassFinalizer(Class @class) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!Options.GenerateFinalizers) |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PushBlock(CLIBlockKind.Finalizer); |
|
|
|
PushBlock(CLIBlockKind.Finalizer); |
|
|
|
WriteLine("!{0}();", @class.Name); |
|
|
|
WriteLine("!{0}();", @class.Name); |
|
|
|
PopBlock(NewLineKind.BeforeNextBlock); |
|
|
|
PopBlock(NewLineKind.BeforeNextBlock); |
|
|
@ -415,7 +414,7 @@ namespace CppSharp.Generators.CLI |
|
|
|
{ |
|
|
|
{ |
|
|
|
// Handle the case of struct (value-type) inheritance by adding the base
|
|
|
|
// Handle the case of struct (value-type) inheritance by adding the base
|
|
|
|
// properties to the managed value subtypes.
|
|
|
|
// properties to the managed value subtypes.
|
|
|
|
if (@class.IsValueType) |
|
|
|
if (@class.IsValueType) |
|
|
|
{ |
|
|
|
{ |
|
|
|
foreach (var @base in @class.Bases.Where(b => b.IsClass && b.Class.IsDeclared)) |
|
|
|
foreach (var @base in @class.Bases.Where(b => b.IsClass && b.Class.IsDeclared)) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -447,14 +446,14 @@ namespace CppSharp.Generators.CLI |
|
|
|
field.Offset); |
|
|
|
field.Offset); |
|
|
|
WriteLine("{0} {1};", field.Type, field.Name); |
|
|
|
WriteLine("{0} {1};", field.Type, field.Name); |
|
|
|
|
|
|
|
|
|
|
|
PopBlock(); |
|
|
|
PopBlock(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void GenerateClassEvents(Class @class) |
|
|
|
public void GenerateClassEvents(Class @class) |
|
|
|
{ |
|
|
|
{ |
|
|
|
foreach (var @event in @class.Events) |
|
|
|
foreach (var @event in @class.Events) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!@event.IsGenerated) continue; |
|
|
|
if (!@event.IsGenerated) continue; |
|
|
|
|
|
|
|
|
|
|
|
var cppTypePrinter = new CppTypePrinter(Driver.TypeDatabase); |
|
|
|
var cppTypePrinter = new CppTypePrinter(Driver.TypeDatabase); |
|
|
|
var cppArgs = cppTypePrinter.VisitParameters(@event.Parameters, hasNames: true); |
|
|
|
var cppArgs = cppTypePrinter.VisitParameters(@event.Parameters, hasNames: true); |
|
|
@ -494,7 +493,7 @@ namespace CppSharp.Generators.CLI |
|
|
|
|
|
|
|
|
|
|
|
var staticMethods = new List<Method>(); |
|
|
|
var staticMethods = new List<Method>(); |
|
|
|
foreach (var method in @class.Methods) |
|
|
|
foreach (var method in @class.Methods) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (ASTUtils.CheckIgnoreMethod(method, Options)) |
|
|
|
if (ASTUtils.CheckIgnoreMethod(method, Options)) |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
|
@ -522,7 +521,7 @@ namespace CppSharp.Generators.CLI |
|
|
|
|
|
|
|
|
|
|
|
foreach(var variable in @class.Variables) |
|
|
|
foreach(var variable in @class.Variables) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!variable.IsGenerated) continue; |
|
|
|
if (!variable.IsGenerated) continue; |
|
|
|
|
|
|
|
|
|
|
|
if (variable.Access != AccessSpecifier.Public) |
|
|
|
if (variable.Access != AccessSpecifier.Public) |
|
|
|
continue; |
|
|
|
continue; |
|
|
@ -590,7 +589,7 @@ namespace CppSharp.Generators.CLI |
|
|
|
{ |
|
|
|
{ |
|
|
|
// Handle the case of struct (value-type) inheritance by adding the base
|
|
|
|
// Handle the case of struct (value-type) inheritance by adding the base
|
|
|
|
// properties to the managed value subtypes.
|
|
|
|
// properties to the managed value subtypes.
|
|
|
|
if (@class.IsValueType) |
|
|
|
if (@class.IsValueType) |
|
|
|
{ |
|
|
|
{ |
|
|
|
foreach (var @base in @class.Bases.Where(b => b.IsClass && b.Class.IsDeclared)) |
|
|
|
foreach (var @base in @class.Bases.Where(b => b.IsClass && b.Class.IsDeclared)) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -615,18 +614,18 @@ namespace CppSharp.Generators.CLI |
|
|
|
|
|
|
|
|
|
|
|
public void GenerateIndexer(Property property) |
|
|
|
public void GenerateIndexer(Property property) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var type = property.QualifiedType.Visit(TypePrinter); |
|
|
|
var type = property.QualifiedType.Visit(TypePrinter); |
|
|
|
var getter = property.GetMethod; |
|
|
|
var getter = property.GetMethod; |
|
|
|
var indexParameter = getter.Parameters[0]; |
|
|
|
var indexParameter = getter.Parameters[0]; |
|
|
|
var indexParameterType = indexParameter.QualifiedType.Visit(TypePrinter); |
|
|
|
var indexParameterType = indexParameter.QualifiedType.Visit(TypePrinter); |
|
|
|
|
|
|
|
|
|
|
|
WriteLine("property {0} default[{1}]", type, indexParameterType); |
|
|
|
WriteLine("property {0} default[{1}]", type, indexParameterType); |
|
|
|
WriteStartBraceIndent(); |
|
|
|
WriteStartBraceIndent(); |
|
|
|
|
|
|
|
|
|
|
|
if (property.HasGetter) |
|
|
|
if (property.HasGetter) |
|
|
|
WriteLine("{0} get({1} {2});", type, indexParameterType, indexParameter.Name); |
|
|
|
WriteLine("{0} get({1} {2});", type, indexParameterType, indexParameter.Name); |
|
|
|
|
|
|
|
|
|
|
|
if (property.HasSetter) |
|
|
|
if (property.HasSetter) |
|
|
|
WriteLine("void set({1} {2}, {0} value);", type, indexParameterType, indexParameter.Name); |
|
|
|
WriteLine("void set({1} {2}, {0} value);", type, indexParameterType, indexParameter.Name); |
|
|
|
|
|
|
|
|
|
|
|
WriteCloseBraceIndent(); |
|
|
|
WriteCloseBraceIndent(); |
|
|
@ -638,9 +637,9 @@ namespace CppSharp.Generators.CLI |
|
|
|
return; |
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
PushBlock(CLIBlockKind.Property, property); |
|
|
|
PushBlock(CLIBlockKind.Property, property); |
|
|
|
var type = property.QualifiedType.Visit(TypePrinter); |
|
|
|
var type = property.QualifiedType.Visit(TypePrinter); |
|
|
|
|
|
|
|
|
|
|
|
if (property.IsStatic) |
|
|
|
if (property.IsStatic) |
|
|
|
Write("static "); |
|
|
|
Write("static "); |
|
|
|
|
|
|
|
|
|
|
|
if (property.IsIndexer) |
|
|
|
if (property.IsIndexer) |
|
|
@ -679,9 +678,9 @@ namespace CppSharp.Generators.CLI |
|
|
|
Operators.IsBuiltinOperator(method.OperatorKind); |
|
|
|
Operators.IsBuiltinOperator(method.OperatorKind); |
|
|
|
|
|
|
|
|
|
|
|
if (method.IsStatic || isBuiltinOperator) |
|
|
|
if (method.IsStatic || isBuiltinOperator) |
|
|
|
Write("static "); |
|
|
|
Write("static "); |
|
|
|
|
|
|
|
|
|
|
|
if (method.OperatorKind == CXXOperatorKind.ExplicitConversion) |
|
|
|
if (method.OperatorKind == CXXOperatorKind.ExplicitConversion) |
|
|
|
Write("explicit "); |
|
|
|
Write("explicit "); |
|
|
|
|
|
|
|
|
|
|
|
if (method.IsConstructor || method.IsDestructor || |
|
|
|
if (method.IsConstructor || method.IsDestructor || |
|
|
@ -705,7 +704,7 @@ namespace CppSharp.Generators.CLI |
|
|
|
|
|
|
|
|
|
|
|
public bool GenerateTypedef(TypedefDecl typedef) |
|
|
|
public bool GenerateTypedef(TypedefDecl typedef) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!typedef.IsGenerated) |
|
|
|
if (!typedef.IsGenerated) |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
|
|
FunctionType function; |
|
|
|
FunctionType function; |
|
|
@ -714,20 +713,20 @@ namespace CppSharp.Generators.CLI |
|
|
|
PushBlock(CLIBlockKind.Typedef, typedef); |
|
|
|
PushBlock(CLIBlockKind.Typedef, typedef); |
|
|
|
GenerateDeclarationCommon(typedef); |
|
|
|
GenerateDeclarationCommon(typedef); |
|
|
|
|
|
|
|
|
|
|
|
var insideClass = typedef.Namespace is Class; |
|
|
|
var insideClass = typedef.Namespace is Class; |
|
|
|
|
|
|
|
|
|
|
|
var attributedType = typedef.Type.GetPointee() as AttributedType; |
|
|
|
var attributedType = typedef.Type.GetPointee() as AttributedType; |
|
|
|
if (attributedType != null) |
|
|
|
if (attributedType != null) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var equivalentFunctionType = attributedType.Equivalent.Type as FunctionType; |
|
|
|
var equivalentFunctionType = attributedType.Equivalent.Type as FunctionType; |
|
|
|
var callingConvention = equivalentFunctionType.CallingConvention.ToInteropCallConv(); |
|
|
|
var callingConvention = equivalentFunctionType.CallingConvention.ToInteropCallConv(); |
|
|
|
if (callingConvention != System.Runtime.InteropServices.CallingConvention.Winapi) |
|
|
|
if (callingConvention != System.Runtime.InteropServices.CallingConvention.Winapi) |
|
|
|
{ |
|
|
|
{ |
|
|
|
WriteLine("[{0}({1}::{2})] ", |
|
|
|
WriteLine("[{0}({1}::{2})] ", |
|
|
|
"System::Runtime::InteropServices::UnmanagedFunctionPointer", |
|
|
|
"System::Runtime::InteropServices::UnmanagedFunctionPointer", |
|
|
|
"System::Runtime::InteropServices::CallingConvention", |
|
|
|
"System::Runtime::InteropServices::CallingConvention", |
|
|
|
callingConvention); |
|
|
|
callingConvention); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
WriteLine("{0}{1};", |
|
|
|
WriteLine("{0}{1};", |
|
|
@ -744,7 +743,7 @@ namespace CppSharp.Generators.CLI |
|
|
|
|
|
|
|
|
|
|
|
public void GenerateFunction(Function function) |
|
|
|
public void GenerateFunction(Function function) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!function.IsGenerated) |
|
|
|
if (!function.IsGenerated) |
|
|
|
return; |
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
PushBlock(CLIBlockKind.Function, function); |
|
|
|
PushBlock(CLIBlockKind.Function, function); |
|
|
@ -763,7 +762,7 @@ namespace CppSharp.Generators.CLI |
|
|
|
|
|
|
|
|
|
|
|
public void GenerateEnum(Enumeration @enum) |
|
|
|
public void GenerateEnum(Enumeration @enum) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!@enum.IsGenerated || @enum.IsIncomplete) |
|
|
|
if (!@enum.IsGenerated || @enum.IsIncomplete) |
|
|
|
return; |
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
PushBlock(CLIBlockKind.Enum, @enum); |
|
|
|
PushBlock(CLIBlockKind.Enum, @enum); |
|
|
|