Browse Source

Extended the searching for type maps to try both qualified and unqualified names and both full template declarations and just templated types.

Signed-off-by: Dimitar Dobrev <dpldobrev@yahoo.com>
pull/119/head
Dimitar Dobrev 12 years ago
parent
commit
84fba50cf6
  1. 26
      src/Generator/Types/TypeMap.cs
  2. 10
      tests/CSharpTemp/CSharpTemp.cpp
  3. 22
      tests/CSharpTemp/CSharpTemp.cs
  4. 9
      tests/CSharpTemp/CSharpTemp.h

26
src/Generator/Types/TypeMap.cs

@ -134,24 +134,36 @@ namespace CppSharp.Types @@ -134,24 +134,36 @@ namespace CppSharp.Types
public bool FindTypeMap(Type type, out TypeMap typeMap)
{
var typePrinter = new CppTypePrinter(this);
var output = type.Visit(typePrinter);
if (FindTypeMap(output, out typeMap))
if (FindTypeMap(type.Visit(typePrinter), out typeMap))
{
typeMap.Type = type;
return true;
}
// Try to strip the global scope resolution operator.
if (output.StartsWith("::"))
output = output.Substring(2);
if (FindTypeMap(output, out typeMap))
typePrinter.PrintLocalName = true;
if (FindTypeMap(type.Visit(typePrinter), out typeMap))
{
typeMap.Type = type;
return true;
}
TemplateSpecializationType template = type as TemplateSpecializationType;
if (template != null)
{
if (FindTypeMap(template.Template.TemplatedDecl.Visit(typePrinter), out typeMap))
{
typeMap.Type = type;
return true;
}
typePrinter.PrintLocalName = false;
if (FindTypeMap(template.Template.TemplatedDecl.Visit(typePrinter), out typeMap))
{
typeMap.Type = type;
return true;
}
}
return false;
}

10
tests/CSharpTemp/CSharpTemp.cpp

@ -140,6 +140,16 @@ int ComplexType::check() @@ -140,6 +140,16 @@ int ComplexType::check()
return 5;
}
QFlags<int> ComplexType::returnsQFlags()
{
return QFlags<int>();
}
void ComplexType::takesQFlags(const QFlags<int> f)
{
}
ComplexType P::complexType()
{
return m_complexType;

22
tests/CSharpTemp/CSharpTemp.cs

@ -1,10 +1,32 @@ @@ -1,10 +1,32 @@
using CppSharp.AST;
using CppSharp.Generators;
using CppSharp.Generators.CSharp;
using CppSharp.Passes;
using CppSharp.Types;
using CppSharp.Utils;
namespace CppSharp.Tests
{
[TypeMap("QFlags")]
public class QFlags : TypeMap
{
public override string CSharpSignature(CSharpTypePrinterContext ctx)
{
TemplateArgument templateArgument = ((TemplateSpecializationType) ctx.Type.Desugar()).Arguments[0];
return templateArgument.Type.Type.ToString();
}
public override void CSharpMarshalToNative(MarshalContext ctx)
{
ctx.Return.Write(ctx.Parameter.Name);
}
public override void CSharpMarshalToManaged(MarshalContext ctx)
{
ctx.Return.Write(ctx.ReturnVarName);
}
}
public class CSharpTempTests : LibraryTest
{
public CSharpTempTests(GeneratorKind kind)

9
tests/CSharpTemp/CSharpTemp.h

@ -95,10 +95,19 @@ public: @@ -95,10 +95,19 @@ public:
virtual long prop();
};
template <typename T>
class QFlags
{
public:
QFlags() {}
};
class DLL_API ComplexType
{
public:
int check();
QFlags<int> returnsQFlags();
void takesQFlags(const QFlags<int> f);
};
class DLL_API P : Proprietor

Loading…
Cancel
Save