Browse Source

Merge pull request #119 from ddobrev/master

Fixes on type maps and duplicate names
pull/123/head
João Matos 12 years ago
parent
commit
e9e18f1082
  1. 14
      src/Generator/Generators/CSharp/CSharpTypePrinter.cs
  2. 7
      src/Generator/Passes/CheckDuplicatedNamesPass.cs
  3. 24
      src/Generator/Types/TypeMap.cs
  4. 2
      tests/CSharpTemp/CSharpTemp.Tests.cs
  5. 20
      tests/CSharpTemp/CSharpTemp.cpp
  6. 23
      tests/CSharpTemp/CSharpTemp.cs
  7. 12
      tests/CSharpTemp/CSharpTemp.h

14
src/Generator/Generators/CSharp/CSharpTypePrinter.cs

@ -90,6 +90,20 @@ namespace CppSharp.Generators.CSharp
if (tag.Declaration == null) if (tag.Declaration == null)
return string.Empty; return string.Empty;
TypeMap typeMap;
if (TypeMapDatabase.FindTypeMap(tag.Declaration, out typeMap))
{
typeMap.Type = tag;
Context.CSharpKind = ContextKind;
Context.Type = tag;
return new CSharpTypePrinterResult()
{
Type = typeMap.CSharpSignature(Context),
TypeMap = typeMap
};
}
return tag.Declaration.Visit(this); return tag.Declaration.Visit(this);
} }

7
src/Generator/Passes/CheckDuplicatedNamesPass.cs

@ -46,7 +46,7 @@ namespace CppSharp.Passes
return true; return true;
} }
private bool UpdateName(Function method) private bool UpdateName(Method method)
{ {
var @params = method.Parameters.Where(p => p.Kind != ParameterKind.IndirectReturnType) var @params = method.Parameters.Where(p => p.Kind != ParameterKind.IndirectReturnType)
.Select(p => p.QualifiedType.ToString()); .Select(p => p.QualifiedType.ToString());
@ -72,6 +72,11 @@ namespace CppSharp.Passes
Driver.Diagnostics.EmitWarning("Duplicate operator {0} ignored", method.Name); Driver.Diagnostics.EmitWarning("Duplicate operator {0} ignored", method.Name);
method.ExplicityIgnored = true; method.ExplicityIgnored = true;
} }
else if (method.IsConstructor)
{
Driver.Diagnostics.EmitWarning("Duplicate constructor {0} ignored", method.Name);
method.ExplicityIgnored = true;
}
else else
method.Name += methodCount.ToString(CultureInfo.InvariantCulture); method.Name += methodCount.ToString(CultureInfo.InvariantCulture);
return true; return true;

24
src/Generator/Types/TypeMap.cs

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

2
tests/CSharpTemp/CSharpTemp.Tests.cs

@ -68,7 +68,7 @@ public class CSharpTempTests
Assert.That(proprietor.Value, Is.EqualTo(20)); Assert.That(proprietor.Value, Is.EqualTo(20));
proprietor.Prop = 50; proprietor.Prop = 50;
Assert.That(proprietor.Prop, Is.EqualTo(50)); Assert.That(proprietor.Prop, Is.EqualTo(50));
var p = new P(); var p = new P(null);
p.Value = 20; p.Value = 20;
Assert.That(p.Value, Is.EqualTo(30)); Assert.That(p.Value, Is.EqualTo(30));
p.Prop = 50; p.Prop = 50;

20
tests/CSharpTemp/CSharpTemp.cpp

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

23
tests/CSharpTemp/CSharpTemp.cs

@ -1,10 +1,33 @@
using CppSharp.AST; using CppSharp.AST;
using CppSharp.Generators; using CppSharp.Generators;
using CppSharp.Generators.CSharp;
using CppSharp.Passes; using CppSharp.Passes;
using CppSharp.Types;
using CppSharp.Utils; using CppSharp.Utils;
namespace CppSharp.Tests 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 class CSharpTempTests : LibraryTest
{ {
public CSharpTempTests(GeneratorKind kind) public CSharpTempTests(GeneratorKind kind)

12
tests/CSharpTemp/CSharpTemp.h

@ -95,15 +95,27 @@ public:
virtual long prop(); virtual long prop();
}; };
template <typename T>
class QFlags
{
public:
QFlags() {}
};
class DLL_API ComplexType class DLL_API ComplexType
{ {
public: public:
int check(); int check();
QFlags<int> returnsQFlags();
void takesQFlags(const QFlags<int> f);
}; };
class DLL_API P : Proprietor class DLL_API P : Proprietor
{ {
public: public:
P(const Qux& qux);
P(Qux* qux);
virtual void setValue(int value); virtual void setValue(int value);
virtual long prop(); virtual long prop();

Loading…
Cancel
Save