Browse Source

Fixed the generated code for default value of 0 to a class mapped to an enum.

Signed-off-by: Dimitar Dobrev <dpldobrev@yahoo.com>
pull/376/head
Dimitar Dobrev 12 years ago
parent
commit
191821b1d4
  1. 8
      src/Generator/Passes/HandleDefaultParamValuesPass.cs
  2. 9
      src/Generator/Passes/ParamTypeToInterfacePass.cs
  3. 10
      src/Generator/Types/TypeMap.cs
  4. 9
      tests/CSharpTemp/CSharpTemp.cpp
  5. 11
      tests/CSharpTemp/CSharpTemp.cs
  6. 3
      tests/CSharpTemp/CSharpTemp.h

8
src/Generator/Passes/HandleDefaultParamValuesPass.cs

@ -78,6 +78,7 @@ namespace CppSharp.Passes
if (Driver.TypeDatabase.FindTypeMap(decl, type, out typeMap)) if (Driver.TypeDatabase.FindTypeMap(decl, type, out typeMap))
{ {
Type typeInSignature;
string mappedTo; string mappedTo;
if (Driver.Options.IsCSharpGenerator) if (Driver.Options.IsCSharpGenerator)
{ {
@ -86,6 +87,7 @@ namespace CppSharp.Passes
CSharpKind = CSharpTypePrinterContextKind.Managed, CSharpKind = CSharpTypePrinterContextKind.Managed,
Type = type Type = type
}; };
typeInSignature = typeMap.CSharpSignatureType(typePrinterContext).SkipPointerRefs();
mappedTo = typeMap.CSharpSignature(typePrinterContext); mappedTo = typeMap.CSharpSignature(typePrinterContext);
} }
else else
@ -94,8 +96,14 @@ namespace CppSharp.Passes
{ {
Type = type Type = type
}; };
typeInSignature = typeMap.CLISignatureType(typePrinterContext).SkipPointerRefs();
mappedTo = typeMap.CLISignature(typePrinterContext); mappedTo = typeMap.CLISignature(typePrinterContext);
} }
Enumeration @enum;
if (typeInSignature.TryGetEnum(out @enum))
{
return true;
}
if (mappedTo == "string" && ctor.Parameters.Count == 0) if (mappedTo == "string" && ctor.Parameters.Count == 0)
{ {
parameter.DefaultArgument.String = "\"\""; parameter.DefaultArgument.String = "\"\"";

9
src/Generator/Passes/ParamTypeToInterfacePass.cs

@ -1,4 +1,5 @@
using CppSharp.AST; using CppSharp.AST;
using CppSharp.AST.Extensions;
namespace CppSharp.Passes namespace CppSharp.Passes
{ {
@ -19,13 +20,7 @@ namespace CppSharp.Passes
private static void ChangeToInterfaceType(QualifiedType type) private static void ChangeToInterfaceType(QualifiedType type)
{ {
var tagType = type.Type as TagType; var tagType = type.Type.SkipPointerRefs() as TagType;
if (tagType == null)
{
var pointerType = type.Type as PointerType;
if (pointerType != null)
tagType = pointerType.Pointee as TagType;
}
if (tagType != null) if (tagType != null)
{ {
var @class = tagType.Declaration as Class; var @class = tagType.Declaration as Class;

10
src/Generator/Types/TypeMap.cs

@ -57,6 +57,11 @@ namespace CppSharp.Types
#region C# backend #region C# backend
public virtual Type CSharpSignatureType(CSharpTypePrinterContext ctx)
{
return new CILType(typeof(object));
}
public virtual string CSharpSignature(CSharpTypePrinterContext ctx) public virtual string CSharpSignature(CSharpTypePrinterContext ctx)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
@ -85,6 +90,11 @@ namespace CppSharp.Types
#region C++/CLI backend #region C++/CLI backend
public virtual Type CLISignatureType(CLITypePrinterContext ctx)
{
return new CILType(typeof(object));
}
public virtual string CLISignature(CLITypePrinterContext ctx) public virtual string CLISignature(CLITypePrinterContext ctx)
{ {
throw new NotImplementedException(); throw new NotImplementedException();

9
tests/CSharpTemp/CSharpTemp.cpp

@ -135,6 +135,11 @@ QFlags<T>::QFlags(T t) : flag(t)
{ {
} }
template <typename T>
QFlags<T>::QFlags(Zero) : flag(0)
{
}
template <typename T> template <typename T>
QFlags<T>::operator T() QFlags<T>::operator T()
{ {
@ -285,6 +290,10 @@ void MethodsWithDefaultValues::defaultMappedToEnum(QFlags<Flags> qFlags)
{ {
} }
void MethodsWithDefaultValues::defaultMappedToZeroEnum(QFlags<Flags> qFlags)
{
}
void MethodsWithDefaultValues::defaultIntWithLongExpression(unsigned int i) void MethodsWithDefaultValues::defaultIntWithLongExpression(unsigned int i)
{ {
} }

11
tests/CSharpTemp/CSharpTemp.cs

@ -7,6 +7,7 @@ using CppSharp.Passes;
using CppSharp.Types; using CppSharp.Types;
using CppSharp.Utils; using CppSharp.Utils;
using Attribute = CppSharp.AST.Attribute; using Attribute = CppSharp.AST.Attribute;
using Type = CppSharp.AST.Type;
namespace CppSharp.Tests namespace CppSharp.Tests
{ {
@ -18,11 +19,15 @@ namespace CppSharp.Tests
return string.Empty; return string.Empty;
} }
public override Type CSharpSignatureType(CSharpTypePrinterContext ctx)
{
var templateArgument = ((TemplateSpecializationType) ctx.Type.Desugar()).Arguments[0];
return templateArgument.Type.Type;
}
public override string CSharpSignature(CSharpTypePrinterContext ctx) public override string CSharpSignature(CSharpTypePrinterContext ctx)
{ {
TemplateArgument templateArgument = return this.CSharpSignatureType(ctx).ToString();
((TemplateSpecializationType) ctx.Type.Desugar()).Arguments[0];
return templateArgument.Type.Type.ToString();
} }
public override void CSharpMarshalToNative(MarshalContext ctx) public override void CSharpMarshalToNative(MarshalContext ctx)

3
tests/CSharpTemp/CSharpTemp.h

@ -106,8 +106,10 @@ Proprietor::Proprietor() {}
template <typename T> template <typename T>
class DLL_API QFlags class DLL_API QFlags
{ {
typedef int (*Zero);
public: public:
QFlags(T t); QFlags(T t);
QFlags(Zero);
operator T(); operator T();
private: private:
T flag; T flag;
@ -233,6 +235,7 @@ public:
void defaultEnumAssignedBitwiseOrShort(UntypedFlags flags = Flag1 | Flag2); void defaultEnumAssignedBitwiseOrShort(UntypedFlags flags = Flag1 | Flag2);
void defaultNonEmptyCtor(QGenericArgument arg = QGenericArgument(0)); void defaultNonEmptyCtor(QGenericArgument arg = QGenericArgument(0));
void defaultMappedToEnum(QFlags<Flags> qFlags = Flags::Flag1); void defaultMappedToEnum(QFlags<Flags> qFlags = Flags::Flag1);
void defaultMappedToZeroEnum(QFlags<Flags> qFlags = 0);
void defaultIntWithLongExpression(unsigned int i = DEFAULT_INT); void defaultIntWithLongExpression(unsigned int i = DEFAULT_INT);
}; };

Loading…
Cancel
Save