Skip to content

Commit 567a0df

Browse files
committed
Fix FunctionToInstanceMethod
1 parent fd058db commit 567a0df

File tree

5 files changed

+19
-8
lines changed

5 files changed

+19
-8
lines changed

src/Generator/Generators/CSharp/CSharpMarshal.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -728,14 +728,6 @@ public override bool VisitClassDecl(Class @class)
728728
private void MarshalRefClass(Class @class)
729729
{
730730
var method = Context.Function as Method;
731-
if (method != null
732-
&& method.Conversion == MethodConversionKind.FunctionToInstanceMethod
733-
&& Context.ParameterIndex == 0)
734-
{
735-
Context.Return.Write("{0}", Helpers.InstanceIdentifier);
736-
return;
737-
}
738-
739731
string param = Context.Parameter.Name;
740732
Type type = Context.Parameter.Type.Desugar(resolveTemplateSubstitution: false);
741733
string paramInstance;

tests/CSharp/CSharp.Gen.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ public override void Setup(Driver driver)
3131
public override void SetupPasses(Driver driver)
3232
{
3333
driver.Context.TranslationUnitPasses.AddPass(new TestAttributesPass());
34+
var moveFunctionToClassPass = driver.Context.TranslationUnitPasses.FindPass<MoveFunctionToClassPass>();
35+
driver.Context.TranslationUnitPasses.RemovePass(moveFunctionToClassPass);
36+
driver.Context.TranslationUnitPasses.AddPass(new FunctionToInstanceMethodPass());
37+
driver.Context.TranslationUnitPasses.AddPass(new MoveFunctionToClassPass());
3438
driver.Options.MarshalCharAsManagedChar = true;
3539
driver.Options.GenerateDefaultValuesForArguments = true;
3640
driver.Options.GenerateClassTemplates = true;

tests/CSharp/CSharp.Tests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1894,6 +1894,13 @@ public void TestFunctionToStaticMethod()
18941894
Assert.That(CSharp.CSharp.TestFunctionToStaticMethodConstRefStruct(new FTIStruct(), new FTIStruct() { A = 6 }), Is.EqualTo(6));
18951895
}
18961896

1897+
[Test]
1898+
public void TestFunctionToInstanceMethod()
1899+
{
1900+
Assert.That(new TestClass().FunctionToInstanceMethod(5), Is.EqualTo(25));
1901+
Assert.That(new TestClass().FunctionToInstanceMethod(new FTIStruct() { A = 5 }), Is.EqualTo(25));
1902+
}
1903+
18971904
[TestCase(typeof(FTIStruct), ExpectedResult = true)]
18981905
[TestCase(typeof(ClassWithoutNativeToManaged), ExpectedResult = false)]
18991906
public bool TestClassGenerateNativeToManaged(Type type)

tests/CSharp/CSharp.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1692,6 +1692,9 @@ DLL_API int TestFunctionToStaticMethodRefStruct(FTIStruct* bb, FTIStruct& defaul
16921692
DLL_API int TestFunctionToStaticMethodConstStruct(FTIStruct* bb, const FTIStruct defaultValue) { return defaultValue.a; }
16931693
DLL_API int TestFunctionToStaticMethodConstRefStruct(FTIStruct* bb, const FTIStruct& defaultValue) { return defaultValue.a; }
16941694

1695+
DLL_API int TestClassFunctionToInstanceMethod(TestClass* bb, int value) { return value * value; }
1696+
DLL_API int TestClassFunctionToInstanceMethod(TestClass* bb, FTIStruct& value) { return value.a * value.a; }
1697+
16951698
int RuleOfThreeTester::constructorCalls = 0;
16961699
int RuleOfThreeTester::destructorCalls = 0;
16971700
int RuleOfThreeTester::copyConstructorCalls = 0;

tests/CSharp/CSharp.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,6 +1535,11 @@ DLL_API int TestFunctionToStaticMethodRefStruct(FTIStruct* bb, FTIStruct& defaul
15351535
DLL_API int TestFunctionToStaticMethodConstStruct(FTIStruct* bb, const FTIStruct defaultValue);
15361536
DLL_API int TestFunctionToStaticMethodConstRefStruct(FTIStruct* bb, const FTIStruct& defaultValue);
15371537

1538+
class DLL_API TestClass { int a; };
1539+
1540+
DLL_API int TestClassFunctionToInstanceMethod(TestClass* bb, int value);
1541+
DLL_API int TestClassFunctionToInstanceMethod(TestClass* bb, FTIStruct& cc);
1542+
15381543
class ClassWithoutNativeToManaged { };
15391544

15401545
struct DLL_API ClassWithIntValue {

0 commit comments

Comments
 (0)