From 7dcc4e15065fbf87a5ee9dad76ad823775837768 Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Tue, 12 Nov 2013 12:34:45 +0200 Subject: [PATCH 1/3] Checked for type maps of tag types. Signed-off-by: Dimitar Dobrev --- .../Generators/CSharp/CSharpTypePrinter.cs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/Generator/Generators/CSharp/CSharpTypePrinter.cs b/src/Generator/Generators/CSharp/CSharpTypePrinter.cs index 1e2929d2..d1f3d301 100644 --- a/src/Generator/Generators/CSharp/CSharpTypePrinter.cs +++ b/src/Generator/Generators/CSharp/CSharpTypePrinter.cs @@ -87,8 +87,22 @@ namespace CppSharp.Generators.CSharp public CSharpTypePrinterResult VisitTagType(TagType tag, TypeQualifiers quals) { - if (tag.Declaration == null) - return string.Empty; + if (tag.Declaration == null) + 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); } From 84fba50cf6dd8d3ad59f7ef626f10bd4d7b60865 Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Tue, 12 Nov 2013 12:35:59 +0200 Subject: [PATCH 2/3] 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 --- src/Generator/Types/TypeMap.cs | 26 +++++++++++++++++++------- tests/CSharpTemp/CSharpTemp.cpp | 10 ++++++++++ tests/CSharpTemp/CSharpTemp.cs | 22 ++++++++++++++++++++++ tests/CSharpTemp/CSharpTemp.h | 9 +++++++++ 4 files changed, 60 insertions(+), 7 deletions(-) diff --git a/src/Generator/Types/TypeMap.cs b/src/Generator/Types/TypeMap.cs index 121d58ec..d1e464d6 100644 --- a/src/Generator/Types/TypeMap.cs +++ b/src/Generator/Types/TypeMap.cs @@ -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; } diff --git a/tests/CSharpTemp/CSharpTemp.cpp b/tests/CSharpTemp/CSharpTemp.cpp index 08de6da0..28dc0ea1 100644 --- a/tests/CSharpTemp/CSharpTemp.cpp +++ b/tests/CSharpTemp/CSharpTemp.cpp @@ -140,6 +140,16 @@ int ComplexType::check() return 5; } +QFlags ComplexType::returnsQFlags() +{ + return QFlags(); +} + +void ComplexType::takesQFlags(const QFlags f) +{ + +} + ComplexType P::complexType() { return m_complexType; diff --git a/tests/CSharpTemp/CSharpTemp.cs b/tests/CSharpTemp/CSharpTemp.cs index 4e1431a9..f841894b 100644 --- a/tests/CSharpTemp/CSharpTemp.cs +++ b/tests/CSharpTemp/CSharpTemp.cs @@ -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) diff --git a/tests/CSharpTemp/CSharpTemp.h b/tests/CSharpTemp/CSharpTemp.h index e2537353..af1bf615 100644 --- a/tests/CSharpTemp/CSharpTemp.h +++ b/tests/CSharpTemp/CSharpTemp.h @@ -95,10 +95,19 @@ public: virtual long prop(); }; +template +class QFlags +{ +public: + QFlags() {} +}; + class DLL_API ComplexType { public: int check(); + QFlags returnsQFlags(); + void takesQFlags(const QFlags f); }; class DLL_API P : Proprietor From 79883199f5803c2113d871318bba54502d05c523 Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Tue, 12 Nov 2013 12:39:07 +0200 Subject: [PATCH 3/3] Prevented the renaming of constructors if there is duplication of names. Signed-off-by: Dimitar Dobrev --- .../Passes/CheckDuplicatedNamesPass.cs | 7 ++++- src/Generator/Types/TypeMap.cs | 28 +++++++++---------- tests/CSharpTemp/CSharpTemp.Tests.cs | 2 +- tests/CSharpTemp/CSharpTemp.cpp | 10 +++++++ tests/CSharpTemp/CSharpTemp.cs | 3 +- tests/CSharpTemp/CSharpTemp.h | 3 ++ 6 files changed, 36 insertions(+), 17 deletions(-) diff --git a/src/Generator/Passes/CheckDuplicatedNamesPass.cs b/src/Generator/Passes/CheckDuplicatedNamesPass.cs index 9a758100..88748b79 100644 --- a/src/Generator/Passes/CheckDuplicatedNamesPass.cs +++ b/src/Generator/Passes/CheckDuplicatedNamesPass.cs @@ -46,7 +46,7 @@ namespace CppSharp.Passes return true; } - private bool UpdateName(Function method) + private bool UpdateName(Method method) { var @params = method.Parameters.Where(p => p.Kind != ParameterKind.IndirectReturnType) .Select(p => p.QualifiedType.ToString()); @@ -72,6 +72,11 @@ namespace CppSharp.Passes Driver.Diagnostics.EmitWarning("Duplicate operator {0} ignored", method.Name); method.ExplicityIgnored = true; } + else if (method.IsConstructor) + { + Driver.Diagnostics.EmitWarning("Duplicate constructor {0} ignored", method.Name); + method.ExplicityIgnored = true; + } else method.Name += methodCount.ToString(CultureInfo.InvariantCulture); return true; diff --git a/src/Generator/Types/TypeMap.cs b/src/Generator/Types/TypeMap.cs index d1e464d6..fd53b3d2 100644 --- a/src/Generator/Types/TypeMap.cs +++ b/src/Generator/Types/TypeMap.cs @@ -135,19 +135,6 @@ namespace CppSharp.Types { var typePrinter = new CppTypePrinter(this); - if (FindTypeMap(type.Visit(typePrinter), out typeMap)) - { - typeMap.Type = type; - return true; - } - - typePrinter.PrintLocalName = true; - if (FindTypeMap(type.Visit(typePrinter), out typeMap)) - { - typeMap.Type = type; - return true; - } - TemplateSpecializationType template = type as TemplateSpecializationType; if (template != null) { @@ -156,7 +143,7 @@ namespace CppSharp.Types typeMap.Type = type; return true; } - typePrinter.PrintLocalName = false; + typePrinter.PrintLocalName = true; if (FindTypeMap(template.Template.TemplatedDecl.Visit(typePrinter), out typeMap)) { typeMap.Type = type; @@ -164,6 +151,19 @@ namespace CppSharp.Types } } + if (FindTypeMap(type.Visit(typePrinter), out typeMap)) + { + typeMap.Type = type; + return true; + } + + typePrinter.PrintLocalName = false; + if (FindTypeMap(type.Visit(typePrinter), out typeMap)) + { + typeMap.Type = type; + return true; + } + return false; } diff --git a/tests/CSharpTemp/CSharpTemp.Tests.cs b/tests/CSharpTemp/CSharpTemp.Tests.cs index a492411c..471b4c88 100644 --- a/tests/CSharpTemp/CSharpTemp.Tests.cs +++ b/tests/CSharpTemp/CSharpTemp.Tests.cs @@ -68,7 +68,7 @@ public class CSharpTempTests Assert.That(proprietor.Value, Is.EqualTo(20)); proprietor.Prop = 50; Assert.That(proprietor.Prop, Is.EqualTo(50)); - var p = new P(); + var p = new P(null); p.Value = 20; Assert.That(p.Value, Is.EqualTo(30)); p.Prop = 50; diff --git a/tests/CSharpTemp/CSharpTemp.cpp b/tests/CSharpTemp/CSharpTemp.cpp index 28dc0ea1..0176736d 100644 --- a/tests/CSharpTemp/CSharpTemp.cpp +++ b/tests/CSharpTemp/CSharpTemp.cpp @@ -150,6 +150,16 @@ void ComplexType::takesQFlags(const QFlags f) } +P::P(const Qux &qux) +{ + +} + +P::P(Qux *qux) +{ + +} + ComplexType P::complexType() { return m_complexType; diff --git a/tests/CSharpTemp/CSharpTemp.cs b/tests/CSharpTemp/CSharpTemp.cs index f841894b..bb473b11 100644 --- a/tests/CSharpTemp/CSharpTemp.cs +++ b/tests/CSharpTemp/CSharpTemp.cs @@ -12,7 +12,8 @@ namespace CppSharp.Tests { public override string CSharpSignature(CSharpTypePrinterContext ctx) { - TemplateArgument templateArgument = ((TemplateSpecializationType) ctx.Type.Desugar()).Arguments[0]; + TemplateArgument templateArgument = + ((TemplateSpecializationType) ctx.Type.Desugar()).Arguments[0]; return templateArgument.Type.Type.ToString(); } diff --git a/tests/CSharpTemp/CSharpTemp.h b/tests/CSharpTemp/CSharpTemp.h index af1bf615..2adec6eb 100644 --- a/tests/CSharpTemp/CSharpTemp.h +++ b/tests/CSharpTemp/CSharpTemp.h @@ -113,6 +113,9 @@ public: class DLL_API P : Proprietor { public: + P(const Qux& qux); + P(Qux* qux); + virtual void setValue(int value); virtual long prop();