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

12
src/Generator/Passes/GetterSetterToPropertyAdvancedPass.cs

@ -25,7 +25,7 @@ namespace CppSharp.Passes @@ -25,7 +25,7 @@ namespace CppSharp.Passes
{
this.log = log;
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);
}
@ -275,11 +275,15 @@ namespace CppSharp.Passes @@ -275,11 +275,15 @@ namespace CppSharp.Passes
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 @@ -59,6 +59,7 @@ namespace CppSharp.Tests
public override void SetupPasses(Driver driver)
{
driver.Options.GenerateAbstractImpls = true;
driver.Options.GenerateInterfacesForMultipleInheritance = true;
driver.Options.GeneratePropertiesAdvanced = true;
driver.Options.GenerateVirtualTables = true;

6
tests/CSharpTemp/CSharpTemp.h

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

Loading…
Cancel
Save