Browse Source

Fixed the generated C# for a property returning a template with a renamed type arg.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/913/head
Dimitar Dobrev 8 years ago
parent
commit
94c0838337
  1. 18
      src/Generator/Generators/CSharp/CSharpMarshal.cs
  2. 15
      src/Generator/Generators/CSharp/CSharpSources.cs
  3. 11
      tests/CSharp/CSharp.Tests.cs
  4. 15
      tests/CSharp/CSharpTemplates.h

18
src/Generator/Generators/CSharp/CSharpMarshal.cs

@ -174,14 +174,18 @@ namespace CppSharp.Generators.CSharp @@ -174,14 +174,18 @@ namespace CppSharp.Generators.CSharp
var type = Context.ReturnType.Type.Desugar(
resolveTemplateSubstitution: false);
if (Context.Function != null &&
Context.Function.OperatorKind == CXXOperatorKind.Subscript &&
type.IsPrimitiveType(primitive))
Context.Function.OperatorKind == CXXOperatorKind.Subscript)
{
var substitute = type as TemplateParameterSubstitutionType;
if (substitute != null)
Context.Return.Write($@"({
substitute.ReplacedParameter.Parameter.Name}) (object) ");
Context.Return.Write("*");
if (type.IsPrimitiveType(primitive))
{
Context.Return.Write("*");
}
else
{
var templateParameter = type as TemplateParameterType;
if (templateParameter != null)
Context.Return.Write($@"({templateParameter.Parameter.Name}) (object) *");
}
}
Context.Return.Write(Context.ReturnVarName);

15
src/Generator/Generators/CSharp/CSharpSources.cs

@ -1086,13 +1086,14 @@ namespace CppSharp.Generators.CSharp @@ -1086,13 +1086,14 @@ namespace CppSharp.Generators.CSharp
@class.Visit(TypePrinter)}."");");
return;
}
property = actualProperty;
if (property.GetMethod.SynthKind == FunctionSynthKind.AbstractImplCall)
GenerateVirtualPropertyCall(property.GetMethod, @class.BaseClass, property);
else if (property.GetMethod.IsVirtual)
GenerateVirtualPropertyCall(property.GetMethod, @class, property);
else GenerateInternalFunctionCall(property.GetMethod,
property.GetMethod.Parameters, property.QualifiedType);
if (actualProperty.GetMethod.SynthKind == FunctionSynthKind.AbstractImplCall)
GenerateVirtualPropertyCall(actualProperty.GetMethod,
@class.BaseClass, actualProperty);
else if (actualProperty.GetMethod.IsVirtual)
GenerateVirtualPropertyCall(actualProperty.GetMethod,
@class, actualProperty);
else GenerateInternalFunctionCall(actualProperty.GetMethod,
actualProperty.GetMethod.Parameters, property.QualifiedType);
}
private static Property GetActualProperty(Property property, Class c)

11
tests/CSharp/CSharp.Tests.cs

@ -831,6 +831,17 @@ public unsafe class CSharpTests : GeneratorTestFixture @@ -831,6 +831,17 @@ public unsafe class CSharpTests : GeneratorTestFixture
}
}
[Test]
public void TestPropertyReturnsTemplateWithRenamedTypeArg()
{
using (var hasDefaultTemplateArgument = new HasDefaultTemplateArgument<int, int>())
{
var returnTemplateWithRenamedTypeArg =
hasDefaultTemplateArgument.PropertyReturnsTemplateWithRenamedTypeArg;
Assert.That(returnTemplateWithRenamedTypeArg.DependentValue, Is.EqualTo(0));
}
}
[Test]
public void TestAbstractImplementatonsInPrimaryAndSecondaryBases()
{

15
tests/CSharp/CSharpTemplates.h

@ -101,7 +101,7 @@ template <typename T> @@ -101,7 +101,7 @@ template <typename T>
class DLL_API DependentValueFieldForArray
{
private:
T field;
T field{};
};
template <typename T>
@ -124,7 +124,7 @@ public: @@ -124,7 +124,7 @@ public:
T getDependentValue();
void setDependentValue(const T& value);
private:
T field;
T field{};
union {
int unionField;
};
@ -205,9 +205,10 @@ public: @@ -205,9 +205,10 @@ public:
static T staticProperty();
static void setStaticProperty(const T& t);
bool operator==(const HasDefaultTemplateArgument& other);
DependentValueFields<D> returnTemplateWithRenamedTypeArg(const DependentValueFields<D> &value);
DependentValueFields<D> returnTemplateWithRenamedTypeArg(const DependentValueFields<D>& value);
DependentValueFields<D> propertyReturnsTemplateWithRenamedTypeArg();
private:
T field;
T field{};
static T staticField;
};
@ -272,6 +273,12 @@ DependentValueFields<D> HasDefaultTemplateArgument<T, D>::returnTemplateWithRena @@ -272,6 +273,12 @@ DependentValueFields<D> HasDefaultTemplateArgument<T, D>::returnTemplateWithRena
return value;
}
template <typename T, typename D>
DependentValueFields<D> HasDefaultTemplateArgument<T, D>::propertyReturnsTemplateWithRenamedTypeArg()
{
return DependentValueFields<D>();
}
template <typename T, typename D>
T HasDefaultTemplateArgument<T, D>::staticField;

Loading…
Cancel
Save