diff --git a/src/Generator/Generators/CLI/CLIMarshal.cs b/src/Generator/Generators/CLI/CLIMarshal.cs index ad493c23..24a4cda2 100644 --- a/src/Generator/Generators/CLI/CLIMarshal.cs +++ b/src/Generator/Generators/CLI/CLIMarshal.cs @@ -30,6 +30,9 @@ namespace CppSharp.Generators.CLI public override bool VisitTagType(TagType tag, TypeQualifiers quals) { + if (!VisitType(tag, quals)) + return false; + var decl = tag.Declaration; return decl.Visit(this); } @@ -90,8 +93,11 @@ namespace CppSharp.Generators.CLI return true; } + TypeMap typeMap = null; + Context.Driver.TypeDatabase.FindTypeMap(pointee, out typeMap); + Class @class; - if (pointee.IsTagDecl(out @class)) + if (pointee.IsTagDecl(out @class) && typeMap == null) { var instance = (pointer.IsReference) ? "&" + Context.ReturnVarName : Context.ReturnVarName; @@ -344,6 +350,9 @@ namespace CppSharp.Generators.CLI public override bool VisitTagType(TagType tag, TypeQualifiers quals) { + if (!VisitType(tag, quals)) + return false; + var decl = tag.Declaration; return decl.Visit(this); } diff --git a/src/Generator/Generators/CLI/CLISourcesTemplate.cs b/src/Generator/Generators/CLI/CLISourcesTemplate.cs index ac983a80..28bf1827 100644 --- a/src/Generator/Generators/CLI/CLISourcesTemplate.cs +++ b/src/Generator/Generators/CLI/CLISourcesTemplate.cs @@ -61,7 +61,7 @@ namespace CppSharp.Generators.CLI var includes = new SortedSet(StringComparer.InvariantCulture); foreach (var typeRef in typeReferenceCollector.TypeReferences) - { + { if (typeRef.Include.File == TranslationUnit.FileName) continue; diff --git a/src/Generator/Generators/CLI/CLITypePrinter.cs b/src/Generator/Generators/CLI/CLITypePrinter.cs index 5a4b1cf8..a1d8b7e1 100644 --- a/src/Generator/Generators/CLI/CLITypePrinter.cs +++ b/src/Generator/Generators/CLI/CLITypePrinter.cs @@ -43,6 +43,14 @@ namespace CppSharp.Generators.CLI public string VisitTagType(TagType tag, TypeQualifiers quals) { + TypeMap typeMap = null; + if (TypeMapDatabase.FindTypeMap(tag, out typeMap)) + { + typeMap.Type = tag; + Context.Type = tag; + return typeMap.CLISignature(Context); + } + Declaration decl = tag.Declaration; if (decl == null) diff --git a/src/Generator/Generators/CLI/CLITypeReferences.cs b/src/Generator/Generators/CLI/CLITypeReferences.cs index ca4b17db..0e56447d 100644 --- a/src/Generator/Generators/CLI/CLITypeReferences.cs +++ b/src/Generator/Generators/CLI/CLITypeReferences.cs @@ -87,27 +87,24 @@ namespace CppSharp.Generators.CLI record.Value.Visit(this); GenerateInclude(record); - ProcessTypeMap(record); } } - private void ProcessTypeMap(ASTRecord record) - { - TypeMap typeMap; - if (!TypeMapDatabase.FindTypeMap(record.Value, out typeMap)) - return; - - - typeMap.Declaration = record.Value; - typeMap.CLITypeReference(this, record); - } - private void GenerateInclude(ASTRecord record) { var decl = record.Value; if(decl.Namespace == null) return; + // Find a type map for the declaration and use it if it exists. + TypeMap typeMap; + if (TypeMapDatabase.FindTypeMap(record.Value, out typeMap)) + { + typeMap.Declaration = record.Value; + typeMap.CLITypeReference(this, record); + return; + } + var declFile = decl.Namespace.TranslationUnit.FileName; if(decl.Namespace.TranslationUnit.IsSystemHeader)