Browse Source

Fixed bugs with abstract properties in abstract impls.

Signed-off-by: Dimitar Dobrev <dpldobrev@yahoo.com>
pull/309/head
Dimitar Dobrev 11 years ago
parent
commit
a5b59f67f8
  1. 59
      src/Generator/Generators/CSharp/CSharpTextTemplate.cs
  2. 12
      src/Generator/Passes/GetterSetterToPropertyAdvancedPass.cs
  3. 1
      tests/CSharpTemp/CSharpTemp.cs
  4. 6
      tests/CSharpTemp/CSharpTemp.h

59
src/Generator/Generators/CSharp/CSharpTextTemplate.cs

@ -852,7 +852,7 @@ namespace CppSharp.Generators.CSharp
return Tuple.Create(library, decl.Mangled); return Tuple.Create(library, decl.Mangled);
} }
private void GeneratePropertySetter<T>(QualifiedType returnType, T decl, Class @class) private void GeneratePropertySetter<T>(QualifiedType returnType, T decl, Class @class, bool isAbstract = false)
where T : Declaration, ITypedDecl where T : Declaration, ITypedDecl
{ {
if (!(decl is Function || decl is Field) ) if (!(decl is Function || decl is Field) )
@ -861,7 +861,7 @@ namespace CppSharp.Generators.CSharp
} }
PushBlock(CSharpBlockKind.Method); PushBlock(CSharpBlockKind.Method);
WriteLine("set"); Write("set");
var param = new Parameter var param = new Parameter
{ {
@ -878,27 +878,28 @@ namespace CppSharp.Generators.CSharp
if (decl is Function) if (decl is Function)
{ {
var function = decl as Function; var function = decl as Function;
if (function.IsPure && Driver.Options.GenerateAbstractImpls) if (isAbstract && Driver.Options.GenerateAbstractImpls)
{ {
Write(";"); Write(";");
PopBlock(NewLineKind.BeforeNextBlock); PopBlock(NewLineKind.BeforeNextBlock);
return; return;
} }
NewLine();
WriteStartBraceIndent(); WriteStartBraceIndent();
if (function.Parameters.Count == 0) if (function.Parameters.Count == 0)
throw new NotSupportedException("Expected at least one parameter in setter"); throw new NotSupportedException("Expected at least one parameter in setter");
param.QualifiedType = function.Parameters[0].QualifiedType; param.QualifiedType = function.Parameters[0].QualifiedType;
var method = function as Method; if (function.SynthKind == FunctionSynthKind.AbstractImplCall)
if (method != null && method.OperatorKind == CXXOperatorKind.Subscript)
{ {
if (method.SynthKind == FunctionSynthKind.AbstractImplCall) GenerateAbstractImplCall(function, @class);
{ }
GenerateAbstractImplCall(method, @class); else
} {
else var method = function as Method;
if (method != null && method.OperatorKind == CXXOperatorKind.Subscript)
{ {
if (method.OperatorKind == CXXOperatorKind.Subscript) if (method.OperatorKind == CXXOperatorKind.Subscript)
{ {
@ -910,11 +911,10 @@ namespace CppSharp.Generators.CSharp
GenerateInternalFunctionCall(function, parameters); GenerateInternalFunctionCall(function, parameters);
} }
} }
} else
else {
{ GenerateInternalFunctionCall(function, new List<Parameter> { param });
var parameters = new List<Parameter> { param }; }
GenerateInternalFunctionCall(function, parameters);
} }
WriteCloseBraceIndent(); WriteCloseBraceIndent();
} }
@ -927,6 +927,7 @@ namespace CppSharp.Generators.CSharp
{ {
if (@class.IsUnion) if (@class.IsUnion)
{ {
NewLine();
WriteStartBraceIndent(); WriteStartBraceIndent();
WriteLine("{0} = value;", decl.Name); WriteLine("{0} = value;", decl.Name);
WriteCloseBraceIndent(); WriteCloseBraceIndent();
@ -938,6 +939,7 @@ namespace CppSharp.Generators.CSharp
return; return;
} }
NewLine();
WriteStartBraceIndent(); WriteStartBraceIndent();
WriteLine("var {0} = (Internal*){1}.ToPointer();", WriteLine("var {0} = (Internal*){1}.ToPointer();",
@ -1001,7 +1003,7 @@ namespace CppSharp.Generators.CSharp
} }
} }
private void GeneratePropertyGetter<T>(QualifiedType returnType, T decl, Class @class) private void GeneratePropertyGetter<T>(QualifiedType returnType, T decl, Class @class, bool isAbstract = false)
where T : Declaration, ITypedDecl where T : Declaration, ITypedDecl
{ {
PushBlock(CSharpBlockKind.Method); PushBlock(CSharpBlockKind.Method);
@ -1010,7 +1012,7 @@ namespace CppSharp.Generators.CSharp
if (decl is Function) if (decl is Function)
{ {
var function = decl as Function; var function = decl as Function;
if (function.IsPure && Driver.Options.GenerateAbstractImpls) if (isAbstract && Driver.Options.GenerateAbstractImpls)
{ {
Write(";"); Write(";");
PopBlock(NewLineKind.BeforeNextBlock); PopBlock(NewLineKind.BeforeNextBlock);
@ -1234,16 +1236,15 @@ namespace CppSharp.Generators.CSharp
GeneratePropertyGetter(prop.QualifiedType, prop.Field, @class); GeneratePropertyGetter(prop.QualifiedType, prop.Field, @class);
if (prop.HasSetter) if (prop.HasSetter)
GeneratePropertySetter(prop.Field.QualifiedType, prop.Field, GeneratePropertySetter(prop.Field.QualifiedType, prop.Field, @class);
@class);
} }
else else
{ {
if (prop.HasGetter) if (prop.HasGetter)
GeneratePropertyGetter(prop.QualifiedType, prop.GetMethod, @class); GeneratePropertyGetter(prop.QualifiedType, prop.GetMethod, @class, prop.IsPure);
if (prop.HasSetter) if (prop.HasSetter)
GeneratePropertySetter(prop.QualifiedType, prop.SetMethod, @class); GeneratePropertySetter(prop.QualifiedType, prop.SetMethod, @class, prop.IsPure);
} }
WriteCloseBraceIndent(); WriteCloseBraceIndent();
@ -1620,9 +1621,9 @@ namespace CppSharp.Generators.CSharp
PopBlock(NewLineKind.Always); PopBlock(NewLineKind.Always);
} }
public string GetVTableMethodDelegateName(Method method) public string GetVTableMethodDelegateName(Function function)
{ {
var nativeId = GetFunctionNativeIdentifier(method); var nativeId = GetFunctionNativeIdentifier(function);
// Trim '@' (if any) because '@' is valid only as the first symbol. // Trim '@' (if any) because '@' is valid only as the first symbol.
nativeId = nativeId.Trim('@'); nativeId = nativeId.Trim('@');
@ -2132,23 +2133,23 @@ namespace CppSharp.Generators.CSharp
} }
} }
private void GenerateAbstractImplCall(Method method, Class @class) private void GenerateAbstractImplCall(Function function, Class @class)
{ {
string delegateId; string delegateId;
Write(GetAbstractCallDelegate(method, @class, out delegateId)); Write(GetAbstractCallDelegate(function, @class, out delegateId));
GenerateFunctionCall(delegateId, method.Parameters, method); GenerateFunctionCall(delegateId, function.Parameters, function);
} }
public string GetAbstractCallDelegate(Method method, Class @class, public string GetAbstractCallDelegate(Function function, Class @class,
out string delegateId) out string delegateId)
{ {
var virtualCallBuilder = new StringBuilder(); var virtualCallBuilder = new StringBuilder();
var i = VTables.GetVTableIndex(method, @class); var i = VTables.GetVTableIndex(function, @class);
virtualCallBuilder.AppendFormat("void* slot = *(void**) ((({0}.Internal*) {1})->vfptr0 + {2} * {3});", virtualCallBuilder.AppendFormat("void* slot = *(void**) ((({0}.Internal*) {1})->vfptr0 + {2} * {3});",
@class.BaseClass.Name, Helpers.InstanceIdentifier, i, Driver.TargetInfo.PointerWidth / 8); @class.BaseClass.Name, Helpers.InstanceIdentifier, i, Driver.TargetInfo.PointerWidth / 8);
virtualCallBuilder.AppendLine(); virtualCallBuilder.AppendLine();
string @delegate = GetVTableMethodDelegateName((Method) method.OriginalFunction); string @delegate = GetVTableMethodDelegateName(function.OriginalFunction);
delegateId = Generator.GeneratedIdentifier(@delegate); delegateId = Generator.GeneratedIdentifier(@delegate);
virtualCallBuilder.AppendFormat( virtualCallBuilder.AppendFormat(

12
src/Generator/Passes/GetterSetterToPropertyAdvancedPass.cs

@ -25,7 +25,7 @@ namespace CppSharp.Passes
{ {
this.log = log; this.log = log;
foreach (var method in @class.Methods.Where( foreach (var method in @class.Methods.Where(
m => !m.IsConstructor && !m.IsDestructor && !m.IsOperator && !m.IsSynthetized)) m => !m.IsConstructor && !m.IsDestructor && !m.IsOperator))
DistributeMethod(method); DistributeMethod(method);
} }
@ -275,11 +275,15 @@ namespace CppSharp.Passes
public override bool VisitClassDecl(Class @class) public override bool VisitClassDecl(Class @class)
{ {
bool result = base.VisitClassDecl(@class); if (!AlreadyVisited(@class))
{
bool result = base.VisitClassDecl(@class);
new PropertyGenerator(@class, Log).GenerateProperties(); new PropertyGenerator(@class, Log).GenerateProperties();
return result; return result;
}
return false;
} }
} }
} }

1
tests/CSharpTemp/CSharpTemp.cs

@ -59,6 +59,7 @@ namespace CppSharp.Tests
public override void SetupPasses(Driver driver) public override void SetupPasses(Driver driver)
{ {
driver.Options.GenerateAbstractImpls = true;
driver.Options.GenerateInterfacesForMultipleInheritance = true; driver.Options.GenerateInterfacesForMultipleInheritance = true;
driver.Options.GeneratePropertiesAdvanced = true; driver.Options.GeneratePropertiesAdvanced = true;
driver.Options.GenerateVirtualTables = true; driver.Options.GenerateVirtualTables = true;

6
tests/CSharpTemp/CSharpTemp.h

@ -198,3 +198,9 @@ class DLL_API HasPrivateOverride : public HasPrivateOverrideBase
private: private:
virtual void privateOverride(int i); virtual void privateOverride(int i);
}; };
class DLL_API AbstractWithProperty
{
public:
virtual int property() = 0;
};

Loading…
Cancel
Save