Browse Source

Fixed destructors signature in MS ABI.

See MicrosoftCXXABI::EmitVirtualDestructorCall in https://github.com/llvm-mirror/clang/blob/master/lib/CodeGen/MicrosoftCXXABI.cpp for the nitty gritty details.
pull/499/head
triton 10 years ago
parent
commit
9b62ec46e6
  1. 3
      src/AST/Function.cs
  2. 9
      src/Generator/Generators/CSharp/CSharpTextTemplate.cs
  3. 15
      src/Generator/Passes/CheckAbiParameters.cs

3
src/AST/Function.cs

@ -25,7 +25,8 @@ namespace CppSharp.AST @@ -25,7 +25,8 @@ namespace CppSharp.AST
{
Regular,
IndirectReturnType,
OperatorParameter
OperatorParameter,
ImplcicitDestructorParameter
}
public class Parameter : Declaration, ITypedDecl

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

@ -1835,8 +1835,13 @@ namespace CppSharp.Generators.CSharp @@ -1835,8 +1835,13 @@ namespace CppSharp.Generators.CSharp
Driver.Symbols.FindLibraryBySymbol(dtor.Mangled, out library))
{
WriteLine("if ({0} || force)", Helpers.OwnsNativeInstanceIdentifier);
WriteLineIndent("Internal.{0}({1});", GetFunctionNativeIdentifier(dtor),
Helpers.InstanceIdentifier);
var implicitArg = string.Empty;
if (dtor.Parameters.Any(parameter =>
parameter.Kind == ParameterKind.ImplcicitDestructorParameter))
implicitArg = ", 0"; // Do not delete instance in MS ABI.
WriteLineIndent("Internal.{0}({1}{2});", GetFunctionNativeIdentifier(dtor),
Helpers.InstanceIdentifier, implicitArg);
}
}
}

15
src/Generator/Passes/CheckAbiParameters.cs

@ -39,15 +39,28 @@ namespace CppSharp.Passes @@ -39,15 +39,28 @@ namespace CppSharp.Passes
PrimitiveType.Void));
}
var method = function as Method;
if (function.HasThisReturn)
{
// This flag should only be true on methods.
var method = (Method) function;
var classType = new QualifiedType(new TagType(method.Namespace),
new TypeQualifiers {IsConst = true});
function.ReturnType = new QualifiedType(new PointerType(classType));
}
// Deleting destructors (default in v-table) accept an i32 bitfield as a
// second parameter.in MS ABI.
if (method != null && method.IsDestructor && Driver.Options.IsMicrosoftAbi)
{
method.Parameters.Add(new Parameter
{
Kind = ParameterKind.ImplcicitDestructorParameter,
QualifiedType = new QualifiedType(new BuiltinType(PrimitiveType.Int)),
Name = "delete"
});
}
// TODO: Handle indirect parameters
return true;

Loading…
Cancel
Save