Browse Source

Improved the searching for type maps to work with typedefs and selected mapped template specialisations.

This makes it possible to map the exact specialisation of basic_string which corresponds to std::string.
This helps when std::string is used as a placeholder (std::vector<std::string>) since it's then finally resolved to the specialisation and not the typedef.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/681/head
Dimitar Dobrev 9 years ago
parent
commit
91c0a38296
  1. 12
      src/Generator/Types/Std/Stdlib.cs
  2. 16
      src/Generator/Types/TypeMap.cs

12
src/Generator/Types/Std/Stdlib.cs

@ -27,7 +27,7 @@ namespace CppSharp.Types.Std @@ -27,7 +27,7 @@ namespace CppSharp.Types.Std
}
}
[TypeMap("std::string")]
[TypeMap("std::basic_string<char, std::char_traits<char>, std::allocator<char>>")]
public class String : TypeMap
{
public override string CLISignature(CLITypePrinterContext ctx)
@ -112,8 +112,12 @@ namespace CppSharp.Types.Std @@ -112,8 +112,12 @@ namespace CppSharp.Types.Std
private static ClassTemplateSpecialization GetBasicString(Type type)
{
var template = (type.GetFinalPointee() ?? type).Desugar();
return ((TemplateSpecializationType) template).GetClassTemplateSpecialization();
var desugared = type.Desugar();
var template = (desugared.GetFinalPointee() ?? desugared).Desugar();
var templateSpecializationType = template as TemplateSpecializationType;
if (templateSpecializationType != null)
return templateSpecializationType.GetClassTemplateSpecialization();
return (ClassTemplateSpecialization) ((TagType) template).Declaration;
}
}
@ -382,7 +386,7 @@ namespace CppSharp.Types.Std @@ -382,7 +386,7 @@ namespace CppSharp.Types.Std
}
}
[TypeMap("std::nullptr_t")]
[TypeMap("std::nullptr_t", GeneratorKind = GeneratorKind.CLI)]
public class NullPtr : TypeMap
{
public override bool DoesMarshalling { get { return false; } }

16
src/Generator/Types/TypeMap.cs

@ -195,6 +195,10 @@ namespace CppSharp.Types @@ -195,6 +195,10 @@ namespace CppSharp.Types
return true;
}
var typedef = decl as TypedefDecl;
if (typedef != null)
return FindTypeMap(typedef.Type, out typeMap);
return false;
}
@ -203,9 +207,15 @@ namespace CppSharp.Types @@ -203,9 +207,15 @@ namespace CppSharp.Types
var typePrinter = new CppTypePrinter { PrintLogicalNames = true };
var template = type as TemplateSpecializationType;
if (template != null && template.Template.TemplatedDecl != null)
return FindTypeMap(template.Template.TemplatedDecl, type,
out typeMap);
if (template != null)
{
var specialization = template.GetClassTemplateSpecialization();
if (specialization != null && FindTypeMap(specialization, type, out typeMap))
return true;
if (template.Template.TemplatedDecl != null)
return FindTypeMap(template.Template.TemplatedDecl, type,
out typeMap);
}
if (FindTypeMap(type.Visit(typePrinter), out typeMap))
{

Loading…
Cancel
Save