Skip to content

Commit

Permalink
Generate valid C# for default args: typedefed refs to enums assigned …
Browse files Browse the repository at this point in the history
…empty ctors

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
  • Loading branch information
ddobrev committed Sep 30, 2021
1 parent 15a5548 commit 0e963aa
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/Generator/Passes/ExpressionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ internal class ExpressionHelper
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();

Expand Down Expand Up @@ -226,7 +227,7 @@ private static bool CheckForDefaultPointer(BindingContext context, Type desugare
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))
Expand Down
1 change: 1 addition & 0 deletions tests/CSharp/CSharp.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ public void TestDefaultArguments()
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();
Expand Down
4 changes: 4 additions & 0 deletions tests/CSharp/CSharp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,10 @@ void MethodsWithDefaultValues::defaultMappedToEnumAssignedWithCtor(QFlags<Flags>
{
}

void MethodsWithDefaultValues::defaultTypedefMappedToEnumRefAssignedWithCtor(const TypedefedFlags& qFlags)
{
}

void MethodsWithDefaultValues::defaultZeroMappedToEnumAssignedWithCtor(DefaultZeroMappedToEnum defaultZeroMappedToEnum)
{
}
Expand Down
2 changes: 2 additions & 0 deletions tests/CSharp/CSharp.h
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,8 @@ class DLL_API MethodsWithDefaultValues : public Quux
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');
Expand Down
5 changes: 3 additions & 2 deletions tests/CSharp/CSharpTemplates.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 0e963aa

Please sign in to comment.