Browse Source

Generated the correct calling convention in the UnmanagedFunctionPointerAttribute of delegates.

Signed-off-by: Dimitar Dobrev <dpldobrev@yahoo.com>
pull/48/head
Dimitar Dobrev 12 years ago
parent
commit
1fc9880be9
  1. 2
      src/AST/Type.cs
  2. 9
      src/Generator/Generators/CSharp/CSharpTextTemplate.cs
  3. 49
      src/Parser/Parser.cpp

2
src/AST/Type.cs

@ -282,6 +282,8 @@ namespace CppSharp.AST
// Argument types. // Argument types.
public List<Parameter> Parameters; public List<Parameter> Parameters;
public CallingConvention CallingConvention { get; set; }
public FunctionType() public FunctionType()
{ {
Parameters = new List<Parameter>(); Parameters = new List<Parameter>();

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

@ -1847,7 +1847,7 @@ namespace CppSharp.Generators.CSharp
GenerateDeclarationCommon(typedef); GenerateDeclarationCommon(typedef);
FunctionType function; FunctionType functionType;
TagType tag; TagType tag;
if (typedef.Type.IsPointerToPrimitiveType(PrimitiveType.Void) if (typedef.Type.IsPointerToPrimitiveType(PrimitiveType.Void)
@ -1857,12 +1857,13 @@ namespace CppSharp.Generators.CSharp
WriteLine("public class " + SafeIdentifier(typedef.Name) + @" { }"); WriteLine("public class " + SafeIdentifier(typedef.Name) + @" { }");
PopBlock(NewLineKind.BeforeNextBlock); PopBlock(NewLineKind.BeforeNextBlock);
} }
else if (typedef.Type.IsPointerTo(out function)) else if (typedef.Type.IsPointerTo(out functionType))
{ {
PushBlock(CSharpBlockKind.Typedef); PushBlock(CSharpBlockKind.Typedef);
WriteLine("[UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]"); WriteLine("[UnmanagedFunctionPointerAttribute(CallingConvention.{0})]",
Helpers.ToCSharpCallConv(functionType.CallingConvention));
WriteLine("public {0};", WriteLine("public {0};",
string.Format(TypePrinter.VisitDelegate(function).Type, string.Format(TypePrinter.VisitDelegate(functionType).Type,
SafeIdentifier(typedef.Name))); SafeIdentifier(typedef.Name)));
PopBlock(NewLineKind.BeforeNextBlock); PopBlock(NewLineKind.BeforeNextBlock);
} }

49
src/Parser/Parser.cpp

@ -1040,6 +1040,30 @@ clang::TypeLoc ResolveTypeLoc(clang::TypeLoc TL, clang::TypeLoc::TypeLocClass Cl
return TL; return TL;
} }
static CppSharp::AST::CallingConvention ConvertCallConv(clang::CallingConv CC)
{
using namespace clang;
switch(CC)
{
case CC_Default:
case CC_C:
return CppSharp::AST::CallingConvention::C;
case CC_X86StdCall:
return CppSharp::AST::CallingConvention::StdCall;
case CC_X86FastCall:
return CppSharp::AST::CallingConvention::FastCall;
case CC_X86ThisCall:
return CppSharp::AST::CallingConvention::ThisCall;
case CC_X86Pascal:
case CC_AAPCS:
case CC_AAPCS_VFP:
return CppSharp::AST::CallingConvention::Unknown;
}
return CppSharp::AST::CallingConvention::Default;
}
CppSharp::AST::Type^ Parser::WalkType(clang::QualType QualType, clang::TypeLoc* TL, CppSharp::AST::Type^ Parser::WalkType(clang::QualType QualType, clang::TypeLoc* TL,
bool DesugarType) bool DesugarType)
{ {
@ -1195,6 +1219,7 @@ CppSharp::AST::Type^ Parser::WalkType(clang::QualType QualType, clang::TypeLoc*
auto F = gcnew CppSharp::AST::FunctionType(); auto F = gcnew CppSharp::AST::FunctionType();
F->ReturnType = GetQualifiedType(FP->getResultType(), F->ReturnType = GetQualifiedType(FP->getResultType(),
WalkType(FP->getResultType(), &RL)); WalkType(FP->getResultType(), &RL));
F->CallingConvention = ConvertCallConv(FP->getCallConv());
for (unsigned i = 0; i < FP->getNumArgs(); ++i) for (unsigned i = 0; i < FP->getNumArgs(); ++i)
{ {
@ -1474,30 +1499,6 @@ clang::CallingConv Parser::GetAbiCallConv(clang::CallingConv CC,
return CC; return CC;
} }
static CppSharp::AST::CallingConvention ConvertCallConv(clang::CallingConv CC)
{
using namespace clang;
switch(CC)
{
case CC_Default:
case CC_C:
return CppSharp::AST::CallingConvention::C;
case CC_X86StdCall:
return CppSharp::AST::CallingConvention::StdCall;
case CC_X86FastCall:
return CppSharp::AST::CallingConvention::FastCall;
case CC_X86ThisCall:
return CppSharp::AST::CallingConvention::ThisCall;
case CC_X86Pascal:
case CC_AAPCS:
case CC_AAPCS_VFP:
return CppSharp::AST::CallingConvention::Unknown;
}
return CppSharp::AST::CallingConvention::Default;
}
static const clang::CodeGen::CGFunctionInfo& GetCodeGenFuntionInfo( static const clang::CodeGen::CGFunctionInfo& GetCodeGenFuntionInfo(
clang::CodeGen::CodeGenTypes* CodeGenTypes, clang::FunctionDecl* FD) clang::CodeGen::CodeGenTypes* CodeGenTypes, clang::FunctionDecl* FD)
{ {

Loading…
Cancel
Save