Browse Source

Generated the proper return statements in the abstract implementations.

Signed-off-by: Dimitar Dobrev <dpldobrev@yahoo.com>
pull/53/head
Dimitar Dobrev 12 years ago
parent
commit
a3869c95c5
  1. 10
      src/Generator/Generators/CSharp/CSharpTextTemplate.cs
  2. 17
      src/Generator/Passes/AbstractImplementationsPass.cs

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

@ -1557,7 +1557,7 @@ namespace CppSharp.Generators.CSharp @@ -1557,7 +1557,7 @@ namespace CppSharp.Generators.CSharp
PopBlock(NewLineKind.BeforeNextBlock);
}
private void GenerateVirtualTableMethodCall(ITypedDecl method, Class @class)
private void GenerateVirtualTableMethodCall(Method method, Class @class)
{
WriteLine("void* vtable = *((void**) __Instance.ToPointer());");
int i;
@ -1570,6 +1570,14 @@ namespace CppSharp.Generators.CSharp @@ -1570,6 +1570,14 @@ namespace CppSharp.Generators.CSharp
break;
}
WriteLine("void* slot = *((void**) vtable + {0} * sizeof(IntPtr));", i);
string @delegate = method.Name + "Delegate";
string delegateId = GeneratedIdentifier(@delegate);
WriteLine("{0} {1} = ({0}) Marshal.GetDelegateForFunctionPointer(new IntPtr(slot), typeof({0}));",
@delegate, delegateId);
if (!method.OriginalReturnType.Type.IsPrimitiveType(PrimitiveType.Void))
Write("return ");
WriteLine("{0}({1});", delegateId, string.Join(", ", method.Parameters.Where(
p => p.Kind != ParameterKind.IndirectReturnType).Select(p => Helpers.SafeIdentifier(p.Name))));
}
private void GenerateOperator(Method method, Class @class)

17
src/Generator/Passes/AbstractImplementationsPass.cs

@ -52,8 +52,21 @@ namespace CppSharp.Passes @@ -52,8 +52,21 @@ namespace CppSharp.Passes
abstractMethods.RemoveAt(i);
}
}
internalImplementation.Methods.AddRange(from abstractMethod in abstractMethods
select new Method(abstractMethod));
foreach (Method abstractMethod in abstractMethods)
{
internalImplementation.Methods.Add(new Method(abstractMethod));
var @delegate = new TypedefDecl { Name = abstractMethod.Name + "Delegate" };
var pointerType = new PointerType();
var functionType = new FunctionType();
functionType.CallingConvention = abstractMethod.CallingConvention;
functionType.ReturnType = abstractMethod.OriginalReturnType;
functionType.Parameters.AddRange(abstractMethod.Parameters.Where(
p => p.Kind != ParameterKind.IndirectReturnType));
pointerType.QualifiedPointee = new QualifiedType(functionType);
@delegate.QualifiedType = new QualifiedType(pointerType);
@delegate.IgnoreFlags = abstractMethod.IgnoreFlags;
internalImplementation.Typedefs.Add(@delegate);
}
internalImplementation.Layout = new ClassLayout(@class.Layout);
var vTableComponents = GetVTableComponents(@class);
for (int i = 0; i < abstractMethods.Count; i++)

Loading…
Cancel
Save