diff --git a/src/Generator/Passes/HandleDefaultParamValuesPass.cs b/src/Generator/Passes/HandleDefaultParamValuesPass.cs index 6901bae7..685007b0 100644 --- a/src/Generator/Passes/HandleDefaultParamValuesPass.cs +++ b/src/Generator/Passes/HandleDefaultParamValuesPass.cs @@ -78,6 +78,7 @@ namespace CppSharp.Passes if (Driver.TypeDatabase.FindTypeMap(decl, type, out typeMap)) { + Type typeInSignature; string mappedTo; if (Driver.Options.IsCSharpGenerator) { @@ -86,6 +87,7 @@ namespace CppSharp.Passes CSharpKind = CSharpTypePrinterContextKind.Managed, Type = type }; + typeInSignature = typeMap.CSharpSignatureType(typePrinterContext).SkipPointerRefs(); mappedTo = typeMap.CSharpSignature(typePrinterContext); } else @@ -94,8 +96,14 @@ namespace CppSharp.Passes { Type = type }; + typeInSignature = typeMap.CLISignatureType(typePrinterContext).SkipPointerRefs(); mappedTo = typeMap.CLISignature(typePrinterContext); } + Enumeration @enum; + if (typeInSignature.TryGetEnum(out @enum)) + { + return true; + } if (mappedTo == "string" && ctor.Parameters.Count == 0) { parameter.DefaultArgument.String = "\"\""; diff --git a/src/Generator/Passes/ParamTypeToInterfacePass.cs b/src/Generator/Passes/ParamTypeToInterfacePass.cs index 86f23875..b83275e4 100644 --- a/src/Generator/Passes/ParamTypeToInterfacePass.cs +++ b/src/Generator/Passes/ParamTypeToInterfacePass.cs @@ -1,4 +1,5 @@ using CppSharp.AST; +using CppSharp.AST.Extensions; namespace CppSharp.Passes { @@ -19,13 +20,7 @@ namespace CppSharp.Passes private static void ChangeToInterfaceType(QualifiedType type) { - var tagType = type.Type as TagType; - if (tagType == null) - { - var pointerType = type.Type as PointerType; - if (pointerType != null) - tagType = pointerType.Pointee as TagType; - } + var tagType = type.Type.SkipPointerRefs() as TagType; if (tagType != null) { var @class = tagType.Declaration as Class; diff --git a/src/Generator/Types/TypeMap.cs b/src/Generator/Types/TypeMap.cs index a03ccac0..c3576dec 100644 --- a/src/Generator/Types/TypeMap.cs +++ b/src/Generator/Types/TypeMap.cs @@ -57,6 +57,11 @@ namespace CppSharp.Types #region C# backend + public virtual Type CSharpSignatureType(CSharpTypePrinterContext ctx) + { + return new CILType(typeof(object)); + } + public virtual string CSharpSignature(CSharpTypePrinterContext ctx) { throw new NotImplementedException(); @@ -85,6 +90,11 @@ namespace CppSharp.Types #region C++/CLI backend + public virtual Type CLISignatureType(CLITypePrinterContext ctx) + { + return new CILType(typeof(object)); + } + public virtual string CLISignature(CLITypePrinterContext ctx) { throw new NotImplementedException(); diff --git a/tests/CSharpTemp/CSharpTemp.cpp b/tests/CSharpTemp/CSharpTemp.cpp index 576218e2..09348260 100644 --- a/tests/CSharpTemp/CSharpTemp.cpp +++ b/tests/CSharpTemp/CSharpTemp.cpp @@ -135,6 +135,11 @@ QFlags::QFlags(T t) : flag(t) { } +template +QFlags::QFlags(Zero) : flag(0) +{ +} + template QFlags::operator T() { @@ -285,6 +290,10 @@ void MethodsWithDefaultValues::defaultMappedToEnum(QFlags qFlags) { } +void MethodsWithDefaultValues::defaultMappedToZeroEnum(QFlags qFlags) +{ +} + void MethodsWithDefaultValues::defaultIntWithLongExpression(unsigned int i) { } diff --git a/tests/CSharpTemp/CSharpTemp.cs b/tests/CSharpTemp/CSharpTemp.cs index 6119a9e5..380c3365 100644 --- a/tests/CSharpTemp/CSharpTemp.cs +++ b/tests/CSharpTemp/CSharpTemp.cs @@ -7,6 +7,7 @@ using CppSharp.Passes; using CppSharp.Types; using CppSharp.Utils; using Attribute = CppSharp.AST.Attribute; +using Type = CppSharp.AST.Type; namespace CppSharp.Tests { @@ -18,11 +19,15 @@ namespace CppSharp.Tests 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) { - TemplateArgument templateArgument = - ((TemplateSpecializationType) ctx.Type.Desugar()).Arguments[0]; - return templateArgument.Type.Type.ToString(); + return this.CSharpSignatureType(ctx).ToString(); } public override void CSharpMarshalToNative(MarshalContext ctx) diff --git a/tests/CSharpTemp/CSharpTemp.h b/tests/CSharpTemp/CSharpTemp.h index cbbfbfda..dfa2a679 100644 --- a/tests/CSharpTemp/CSharpTemp.h +++ b/tests/CSharpTemp/CSharpTemp.h @@ -106,8 +106,10 @@ Proprietor::Proprietor() {} template class DLL_API QFlags { + typedef int (*Zero); public: QFlags(T t); + QFlags(Zero); operator T(); private: T flag; @@ -233,6 +235,7 @@ public: void defaultEnumAssignedBitwiseOrShort(UntypedFlags flags = Flag1 | Flag2); void defaultNonEmptyCtor(QGenericArgument arg = QGenericArgument(0)); void defaultMappedToEnum(QFlags qFlags = Flags::Flag1); + void defaultMappedToZeroEnum(QFlags qFlags = 0); void defaultIntWithLongExpression(unsigned int i = DEFAULT_INT); };