Browse Source

Fix issue with includes not being generated for delegates defined in a different file.

pull/440/head
Chris Spencer 10 years ago
parent
commit
d5d17e3ca1
  1. 23
      build/Tests.lua
  2. 10
      src/Generator/AST/ASTRecord.cs
  3. 2
      src/Generator/Generators/CLI/CLITypeReferences.cs
  4. 1
      tests/Basic/AnotherUnit.cpp
  5. 3
      tests/Basic/AnotherUnit.h
  6. 4
      tests/Basic/Basic.cpp
  7. 3
      tests/Basic/Basic.h
  8. 2
      tests/Basic/premake4.lua

23
build/Tests.lua

@ -12,11 +12,11 @@ function SetupExampleProject() @@ -12,11 +12,11 @@ function SetupExampleProject()
SetupParser()
end
function SetupTestProject(name, file, lib)
function SetupTestProject(name, extraFiles)
SetupTestGeneratorProject(name)
SetupTestNativeProject(name)
SetupTestProjectsCSharp(name)
SetupTestProjectsCLI(name)
SetupTestProjectsCSharp(name, nil, extraFiles)
SetupTestProjectsCLI(name, extraFiles)
end
function SetupTestCSharp(name)
@ -107,7 +107,7 @@ function LinkNUnit() @@ -107,7 +107,7 @@ function LinkNUnit()
}
end
function SetupTestProjectsCSharp(name, depends)
function SetupTestProjectsCSharp(name, depends, extraFiles)
project(name .. ".CSharp")
SetupManagedTestProject()
@ -118,6 +118,11 @@ function SetupTestProjectsCSharp(name, depends) @@ -118,6 +118,11 @@ function SetupTestProjectsCSharp(name, depends)
{
path.join(gendir, name, name .. ".cs"),
}
if extraFiles ~= nil then
for _, file in pairs(extraFiles) do
files { path.join(gendir, name, file .. ".cs") }
end
end
linktable = { "CppSharp.Runtime" }
@ -138,7 +143,7 @@ function SetupTestProjectsCSharp(name, depends) @@ -138,7 +143,7 @@ function SetupTestProjectsCSharp(name, depends)
links { "CppSharp.Runtime" }
end
function SetupTestProjectsCLI(name)
function SetupTestProjectsCLI(name, extraFiles)
if not os.is_windows() then
return
end
@ -156,8 +161,14 @@ function SetupTestProjectsCLI(name) @@ -156,8 +161,14 @@ function SetupTestProjectsCLI(name)
files
{
path.join(gendir, name, name .. ".cpp"),
path.join(gendir, name, name .. ".h"),
path.join(gendir, name, name .. ".h")
}
if extraFiles ~= nil then
for _, file in pairs(extraFiles) do
files { path.join(gendir, name, file .. ".cpp") }
files { path.join(gendir, name, file .. ".h") }
end
end
includedirs { path.join(testsdir, name), incdir }
links { name .. ".Native" }

10
src/Generator/AST/ASTRecord.cs

@ -149,6 +149,12 @@ namespace CppSharp.Generators.AST @@ -149,6 +149,12 @@ namespace CppSharp.Generators.AST
Class decl;
return field.Type.Desugar().TryGetClass(out decl) && decl.IsValueType;
}
public static bool IsDelegate(this ASTRecord record)
{
var typedef = record.Object as TypedefDecl;
return typedef != null && typedef.Type.GetPointee() is FunctionType;
}
}
public class RecordCollector : AstVisitor
@ -182,9 +188,7 @@ namespace CppSharp.Generators.AST @@ -182,9 +188,7 @@ namespace CppSharp.Generators.AST
public override bool VisitType(Type type, TypeQualifiers quals)
{
type = type.Desugar();
if(recordStack.Contains(type))
if (recordStack.Contains(type))
return true;
recordStack.Push(type);

2
src/Generator/Generators/CLI/CLITypeReferences.cs

@ -172,7 +172,7 @@ namespace CppSharp.Generators.CLI @@ -172,7 +172,7 @@ namespace CppSharp.Generators.CLI
if (TranslationUnit == record.Value.Namespace.TranslationUnit)
return false;
return record.IsBaseClass() || record.IsFieldValueType();
return record.IsBaseClass() || record.IsFieldValueType() || record.IsDelegate();
}
public override bool VisitDeclaration(Declaration decl)

1
tests/Basic/AnotherUnit.cpp

@ -0,0 +1 @@ @@ -0,0 +1 @@
#include "AnotherUnit.h"

3
tests/Basic/AnotherUnit.h

@ -0,0 +1,3 @@ @@ -0,0 +1,3 @@
#include "../Tests.h"
typedef void (*DelegateInAnotherUnit)();

4
tests/Basic/Basic.cpp

@ -346,6 +346,10 @@ int (*TestDelegates::MarshalAnonymousDelegate4())(int n) @@ -346,6 +346,10 @@ int (*TestDelegates::MarshalAnonymousDelegate4())(int n)
return f;
}
void TestDelegates::MarshalDelegateInAnotherUnit(DelegateInAnotherUnit del)
{
}
std::string HasStdString::testStdString(std::string s)
{
return s + "_test";

3
tests/Basic/Basic.h

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
#include "../Tests.h"
#include "AnotherUnit.h"
#ifdef _WIN32
#include <vadefs.h>
@ -313,6 +314,8 @@ struct DLL_API TestDelegates @@ -313,6 +314,8 @@ struct DLL_API TestDelegates
void MarshalAnonymousDelegate3(float (*del)(float n));
int (*MarshalAnonymousDelegate4())(int n);
void MarshalDelegateInAnotherUnit(DelegateInAnotherUnit del);
DelegateInClass A;
DelegateInGlobalNamespace B;
// As long as we can't marshal them make sure they're ignored

2
tests/Basic/premake4.lua

@ -1,2 +1,2 @@ @@ -1,2 +1,2 @@
group "Tests/Basic"
SetupTestProject("Basic")
SetupTestProject("Basic", { "AnotherUnit" })
Loading…
Cancel
Save