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 9 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
var type = Context.ReturnType.Type.Desugar( var type = Context.ReturnType.Type.Desugar(
resolveTemplateSubstitution: false); resolveTemplateSubstitution: false);
if (Context.Function != null && if (Context.Function != null &&
Context.Function.OperatorKind == CXXOperatorKind.Subscript && Context.Function.OperatorKind == CXXOperatorKind.Subscript)
type.IsPrimitiveType(primitive))
{ {
var substitute = type as TemplateParameterSubstitutionType; if (type.IsPrimitiveType(primitive))
if (substitute != null) {
Context.Return.Write($@"({ Context.Return.Write("*");
substitute.ReplacedParameter.Parameter.Name}) (object) "); }
Context.Return.Write("*"); else
{
var templateParameter = type as TemplateParameterType;
if (templateParameter != null)
Context.Return.Write($@"({templateParameter.Parameter.Name}) (object) *");
}
} }
Context.Return.Write(Context.ReturnVarName); Context.Return.Write(Context.ReturnVarName);

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

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

11
tests/CSharp/CSharp.Tests.cs

@ -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] [Test]
public void TestAbstractImplementatonsInPrimaryAndSecondaryBases() public void TestAbstractImplementatonsInPrimaryAndSecondaryBases()
{ {

15
tests/CSharp/CSharpTemplates.h

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

Loading…
Cancel
Save