Browse Source

Generate valid C# for default args: typedefed refs to enums assigned empty ctors

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/1635/head
Dimitar Dobrev 4 years ago
parent
commit
0e963aa03f
  1. 5
      src/Generator/Passes/ExpressionHelper.cs
  2. 1
      tests/CSharp/CSharp.Tests.cs
  3. 4
      tests/CSharp/CSharp.cpp
  4. 2
      tests/CSharp/CSharp.h
  5. 5
      tests/CSharp/CSharpTemplates.h

5
src/Generator/Passes/ExpressionHelper.cs

@ -19,7 +19,8 @@ namespace CppSharp.Internal @@ -19,7 +19,8 @@ namespace CppSharp.Internal
private static readonly Regex regexDoubleColon = new Regex(@"\w+::", RegexOptions.Compiled);
private static readonly Regex regexName = new Regex(@"(\w+)", RegexOptions.Compiled);
public static bool? PrintExpression(BindingContext context, Function function, Type type, ExpressionObsolete expression, bool allowDefaultLiteral, ref string result)
public static bool? PrintExpression(BindingContext context, Function function, Type type,
ExpressionObsolete expression, bool allowDefaultLiteral, ref string result)
{
var desugared = type.Desugar();
@ -226,7 +227,7 @@ namespace CppSharp.Internal @@ -226,7 +227,7 @@ namespace CppSharp.Internal
private static bool? CheckForDefaultConstruct(BindingContext context, Type desugared, ExpressionObsolete expression,
ref string result)
{
var type = desugared.GetFinalPointee() ?? desugared;
var type = (desugared.GetFinalPointee() ?? desugared).Desugar();
Class decl;
if (!type.TryGetClass(out decl))

1
tests/CSharp/CSharp.Tests.cs

@ -318,6 +318,7 @@ public unsafe class CSharpTests @@ -318,6 +318,7 @@ public unsafe class CSharpTests
Assert.That(methodsWithDefaultValues.DefaultMappedToEnum(), Is.EqualTo(Flags.Flag3));
methodsWithDefaultValues.DefaultMappedToZeroEnum();
methodsWithDefaultValues.DefaultMappedToEnumAssignedWithCtor();
methodsWithDefaultValues.DefaultTypedefMappedToEnumRefAssignedWithCtor();
methodsWithDefaultValues.DefaultZeroMappedToEnumAssignedWithCtor();
Assert.That(methodsWithDefaultValues.DefaultImplicitCtorInt().Priv, Is.EqualTo(0));
methodsWithDefaultValues.DefaultImplicitCtorChar();

4
tests/CSharp/CSharp.cpp

@ -713,6 +713,10 @@ void MethodsWithDefaultValues::defaultMappedToEnumAssignedWithCtor(QFlags<Flags> @@ -713,6 +713,10 @@ void MethodsWithDefaultValues::defaultMappedToEnumAssignedWithCtor(QFlags<Flags>
{
}
void MethodsWithDefaultValues::defaultTypedefMappedToEnumRefAssignedWithCtor(const TypedefedFlags& qFlags)
{
}
void MethodsWithDefaultValues::defaultZeroMappedToEnumAssignedWithCtor(DefaultZeroMappedToEnum defaultZeroMappedToEnum)
{
}

2
tests/CSharp/CSharp.h

@ -452,6 +452,8 @@ public: @@ -452,6 +452,8 @@ public:
QFlags<Flags> defaultMappedToEnum(const QFlags<Flags>& qFlags = Flags::Flag3);
void defaultMappedToZeroEnum(QFlags<Flags> qFlags = 0);
void defaultMappedToEnumAssignedWithCtor(QFlags<Flags> qFlags = QFlags<Flags>());
typedef QFlags<Flags> TypedefedFlags;
void defaultTypedefMappedToEnumRefAssignedWithCtor(const TypedefedFlags& qFlags = TypedefedFlags());
void defaultZeroMappedToEnumAssignedWithCtor(DefaultZeroMappedToEnum defaultZeroMappedToEnum = DefaultZeroMappedToEnum());
Quux defaultImplicitCtorInt(Quux arg = 0);
void defaultImplicitCtorChar(Quux arg = 'a');

5
tests/CSharp/CSharpTemplates.h

@ -698,10 +698,11 @@ template <typename T> @@ -698,10 +698,11 @@ template <typename T>
class QFlags
{
typedef int Int;
typedef int (*Zero);
struct Private;
typedef int (Private::*Zero);
public:
QFlags(T t);
QFlags(Zero = 0);
QFlags(Zero = nullptr);
operator Int();
private:
int flag;

Loading…
Cancel
Save