Browse Source

Import native DLL-s (tests and parser) with MSVC

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/1389/head
Dimitar Dobrev 5 years ago
parent
commit
0e39ab705a
  1. 1
      build/Tests.lua
  2. 2
      src/CppParser/premake5.lua
  3. 1
      src/Generator.Tests/GeneratorTest.cs
  4. 31
      tests/CSharp/CSharpTemplates.h
  5. 70
      tests/Common/Common.cpp
  6. 71
      tests/Common/Common.h
  7. 5
      tests/Tests.h

1
build/Tests.lua

@ -118,6 +118,7 @@ function SetupTestNativeProject(name, depends)
files { "**.h", "**.cpp" } files { "**.h", "**.cpp" }
vpaths { ["*"] = "*" } vpaths { ["*"] = "*" }
defines { "DLL_EXPORT" }
if depends ~= nil then if depends ~= nil then
links { depends .. ".Native" } links { depends .. ".Native" }

2
src/CppParser/premake5.lua

@ -14,6 +14,7 @@ project "CppSharp.CppParser"
language "C++" language "C++"
SetupNativeProject() SetupNativeProject()
rtti "Off" rtti "Off"
defines { "DLL_EXPORT" }
filter "action:vs*" filter "action:vs*"
buildoptions { clang_msvc_flags } buildoptions { clang_msvc_flags }
@ -44,6 +45,7 @@ project "Std-symbols"
language "C++" language "C++"
SetupNativeProject() SetupNativeProject()
rtti "Off" rtti "Off"
defines { "DLL_EXPORT" }
filter { "action:vs*" } filter { "action:vs*" }
buildoptions { clang_msvc_flags } buildoptions { clang_msvc_flags }

1
src/Generator.Tests/GeneratorTest.cs

@ -42,6 +42,7 @@ namespace CppSharp.Utils
var path = Path.GetFullPath(GetTestsDirectory(name)); var path = Path.GetFullPath(GetTestsDirectory(name));
parserOptions.AddIncludeDirs(path); parserOptions.AddIncludeDirs(path);
parserOptions.AddDefines("DLL_EXPORT");
Diagnostics.Message("Looking for tests in: {0}", path); Diagnostics.Message("Looking for tests in: {0}", path);
var files = Directory.EnumerateFiles(path, "*.h"); var files = Directory.EnumerateFiles(path, "*.h");

31
tests/CSharp/CSharpTemplates.h

@ -30,7 +30,7 @@ class DLL_API Ignored
}; };
template <typename T> template <typename T>
class DLL_API IndependentFields : public T1 class IndependentFields : public T1
{ {
typedef T Type; typedef T Type;
public: public:
@ -135,12 +135,12 @@ private:
}; };
template <typename T> template <typename T>
class DLL_API Base class Base
{ {
}; };
template <typename T> template <typename T>
class DLL_API DependentValueFields : public Base<T> class DependentValueFields : public Base<T>
{ {
public: public:
class Nested; class Nested;
@ -245,7 +245,7 @@ public:
}; };
template <typename T> template <typename T>
class DLL_API DependentPointerFields class DependentPointerFields
{ {
public: public:
DependentPointerFields(T t = 0); DependentPointerFields(T t = 0);
@ -284,8 +284,8 @@ public:
class iterator class iterator
{ {
public: public:
iterator() {} iterator();
~iterator() {} ~iterator();
}; };
void takeDependentPtrToFirstTemplateArg(iterator i, const K& k); void takeDependentPtrToFirstTemplateArg(iterator i, const K& k);
void takeDependentPtrToSecondTemplateArg(const V& v); void takeDependentPtrToSecondTemplateArg(const V& v);
@ -294,6 +294,16 @@ private:
V value; V value;
}; };
template <typename K, typename V>
TwoTemplateArgs<K, V>::iterator::iterator()
{
}
template <typename K, typename V>
TwoTemplateArgs<K, V>::iterator::~iterator()
{
}
template <typename K, typename V> template <typename K, typename V>
void TwoTemplateArgs<K, V>::takeDependentPtrToFirstTemplateArg(iterator i, const K& k) void TwoTemplateArgs<K, V>::takeDependentPtrToFirstTemplateArg(iterator i, const K& k)
{ {
@ -305,7 +315,7 @@ void TwoTemplateArgs<K, V>::takeDependentPtrToSecondTemplateArg(const V& v)
} }
template <typename T, typename D = IndependentFields<T>> template <typename T, typename D = IndependentFields<T>>
class DLL_API HasDefaultTemplateArgument class HasDefaultTemplateArgument
{ {
public: public:
HasDefaultTemplateArgument(); HasDefaultTemplateArgument();
@ -638,7 +648,7 @@ public:
}; };
template<typename T> template<typename T>
class DLL_API TemplateDerivedFromRegularDynamic : public RegularDynamic class TemplateDerivedFromRegularDynamic : public RegularDynamic
{ {
public: public:
TemplateDerivedFromRegularDynamic(); TemplateDerivedFromRegularDynamic();
@ -675,7 +685,7 @@ enum class UsedInTemplatedIndexer
}; };
template <typename T> template <typename T>
class DLL_API QFlags class QFlags
{ {
typedef int Int; typedef int Int;
typedef int (*Zero); typedef int (*Zero);
@ -792,6 +802,9 @@ template class DLL_API TemplateWithIndexer<float>;
template class DLL_API TemplateWithIndexer<const char*>; template class DLL_API TemplateWithIndexer<const char*>;
template class DLL_API TemplateDerivedFromRegularDynamic<RegularDynamic>; template class DLL_API TemplateDerivedFromRegularDynamic<RegularDynamic>;
template class DLL_API HasCtorWithMappedToEnum<TestFlag>; template class DLL_API HasCtorWithMappedToEnum<TestFlag>;
template class DLL_API TwoTemplateArgs<int*, int*>;
template class DLL_API TwoTemplateArgs<int*, int>;
template class DLL_API TwoTemplateArgs<int*, float>;
template class DLL_API TwoTemplateArgs<const char*, int>; template class DLL_API TwoTemplateArgs<const char*, int>;
template class DLL_API TwoTemplateArgs<QString, int>; template class DLL_API TwoTemplateArgs<QString, int>;

70
tests/Common/Common.cpp

@ -59,6 +59,10 @@ Foo::Foo(const float& f)
B = f; B = f;
} }
const int Foo::unsafe = 10;
const char Foo::charArray[] = "abc";
int Foo::readWrite = 15;
const char* Foo::GetANSI() const char* Foo::GetANSI()
{ {
return "ANSI"; return "ANSI";
@ -422,6 +426,33 @@ int test(common& s)
return 5; return 5;
} }
int operator *(TestMoveOperatorToClass klass, int b)
{
return klass.A * b;
}
TestMoveOperatorToClass operator-(const TestMoveOperatorToClass& b)
{
TestMoveOperatorToClass nb;
nb.A = -b.A;
nb.B = -b.B;
return nb;
}
TestMoveOperatorToClass operator+(const TestMoveOperatorToClass& b1,
const TestMoveOperatorToClass& b2)
{
TestMoveOperatorToClass b;
b.A = b1.A + b2.A;
b.B = b1.B + b2.B;
return b;
}
int operator==(const Foo2& a, const Foo2& b)
{
return 0;
}
Bar::Item operator |(Bar::Item left, Bar::Item right) Bar::Item operator |(Bar::Item left, Bar::Item right)
{ {
return left | right; return left | right;
@ -501,6 +532,20 @@ ClassD::ClassD(int value)
{ {
} }
decltype(Expr) TestDecltype()
{
return Expr;
}
void TestNullPtrType(decltype(nullptr))
{
}
decltype(nullptr) TestNullPtrTypeRet()
{
return nullptr;
}
void DelegateNamespace::Nested::f1(void (*)()) void DelegateNamespace::Nested::f1(void (*)())
{ {
} }
@ -545,6 +590,11 @@ SomeNamespace::AbstractClass::~AbstractClass()
{ {
} }
int Function()
{
return 5;
}
TestProperties::TestProperties() : Field(0), ArchiveName(0), TestProperties::TestProperties() : Field(0), ArchiveName(0),
FieldValue(0), _refToPrimitiveInSetter(0), FieldValue(0), _refToPrimitiveInSetter(0),
_getterAndSetterWithTheSameName(0), _setterReturnsBoolean(0), _getterAndSetterWithTheSameName(0), _setterReturnsBoolean(0),
@ -776,6 +826,9 @@ Bar& TestIndexedProperties::operator[](const Foo& key)
return bar; return bar;
} }
int TestVariables::VALUE;
void TestVariables::SetValue(int value) { VALUE = value; }
InternalCtorAmbiguity::InternalCtorAmbiguity(void* param) InternalCtorAmbiguity::InternalCtorAmbiguity(void* param)
{ {
// cause a crash to indicate this is the incorrect ctor to invoke // cause a crash to indicate this is the incorrect ctor to invoke
@ -986,10 +1039,27 @@ NonTrivialDtor::~NonTrivialDtor()
dtorCalled = true; dtorCalled = true;
} }
bool NonTrivialDtor::getDtorCalled()
{
return true;
}
void NonTrivialDtor::setDtorCalled(bool value)
{
dtorCalled = true;
}
bool NonTrivialDtor::dtorCalled = false;
DerivedFromTemplateInstantiationWithVirtual::DerivedFromTemplateInstantiationWithVirtual() DerivedFromTemplateInstantiationWithVirtual::DerivedFromTemplateInstantiationWithVirtual()
{ {
} }
int func_union(union_t u)
{
return u.c;
}
HasProtectedEnum::HasProtectedEnum() HasProtectedEnum::HasProtectedEnum()
{ {
} }

71
tests/Common/Common.h

@ -115,11 +115,6 @@ public:
char16_t returnChar16(); char16_t returnChar16();
}; };
// HACK: do not move these to the cpp - C++/CLI is buggy and cannot link static fields initialised in the cpp
const int Foo::unsafe = 10;
int Foo::readWrite = 15;
const char Foo::charArray[] = "abc";
struct DLL_API Bar struct DLL_API Bar
{ {
enum Item enum Item
@ -346,33 +341,15 @@ struct DLL_API TestMoveOperatorToClass
TestMoveOperatorToClass::TestMoveOperatorToClass() {} TestMoveOperatorToClass::TestMoveOperatorToClass() {}
DLL_API int operator *(TestMoveOperatorToClass klass, int b) DLL_API int operator *(TestMoveOperatorToClass klass, int b);
{
return klass.A * b;
}
DLL_API TestMoveOperatorToClass operator-(const TestMoveOperatorToClass& b) DLL_API TestMoveOperatorToClass operator-(const TestMoveOperatorToClass& b);
{
TestMoveOperatorToClass nb;
nb.A = -b.A;
nb.B = -b.B;
return nb;
}
DLL_API TestMoveOperatorToClass operator+(const TestMoveOperatorToClass& b1, DLL_API TestMoveOperatorToClass operator+(const TestMoveOperatorToClass& b1,
const TestMoveOperatorToClass& b2) const TestMoveOperatorToClass& b2);
{
TestMoveOperatorToClass b;
b.A = b1.A + b2.A;
b.B = b1.B + b2.B;
return b;
}
// Not a valid operator overload for Foo2 in managed code - comparison operators need to return bool. // Not a valid operator overload for Foo2 in managed code - comparison operators need to return bool.
DLL_API int operator==(const Foo2& a, const Foo2& b) DLL_API int operator==(const Foo2& a, const Foo2& b);
{
return 0;
}
// Tests delegates // Tests delegates
typedef int (*DelegateInGlobalNamespace)(int); typedef int (*DelegateInGlobalNamespace)(int);
@ -578,10 +555,7 @@ bool ClassWithOverloadedOperators::
} }
// Tests global static function generation // Tests global static function generation
DLL_API int Function() DLL_API int Function();
{
return 5;
}
// Tests properties // Tests properties
struct DLL_API TestProperties struct DLL_API TestProperties
@ -754,9 +728,6 @@ struct DLL_API TestVariables
void SetValue(int value = VALUE); void SetValue(int value = VALUE);
}; };
int TestVariables::VALUE;
void TestVariables::SetValue(int value) { VALUE = value; }
typedef const wchar_t * LPCWSTR; typedef const wchar_t * LPCWSTR;
struct DLL_API TestWideStrings struct DLL_API TestWideStrings
{ {
@ -861,19 +832,11 @@ public:
// Test decltype // Test decltype
int Expr = 0; int Expr = 0;
DLL_API decltype(Expr) TestDecltype() DLL_API decltype(Expr) TestDecltype();
{
return Expr;
}
DLL_API void TestNullPtrType(decltype(nullptr)) DLL_API void TestNullPtrType(decltype(nullptr));
{
}
DLL_API decltype(nullptr) TestNullPtrTypeRet() DLL_API decltype(nullptr) TestNullPtrTypeRet();
{
return nullptr;
}
// Tests dependent name types // Tests dependent name types
template<typename T> struct DependentType template<typename T> struct DependentType
@ -1193,19 +1156,6 @@ private:
static bool dtorCalled; static bool dtorCalled;
}; };
// HACK: do not move these to the cpp - C++/CLI is buggy and cannot link static fields initialised in the cpp
bool NonTrivialDtor::dtorCalled = false;
bool NonTrivialDtor::getDtorCalled()
{
return true;
}
void NonTrivialDtor::setDtorCalled(bool value)
{
dtorCalled = true;
}
template <class T> class ForwardedTemplate; template <class T> class ForwardedTemplate;
ForwardedTemplate<int> returnsForwardedTemplate(); ForwardedTemplate<int> returnsForwardedTemplate();
@ -1255,10 +1205,7 @@ typedef union
int c; int c;
} union_t; } union_t;
int DLL_API func_union(union_t u) int DLL_API func_union(union_t u);
{
return u.c;
}
class DLL_API HasProtectedEnum class DLL_API HasProtectedEnum
{ {

5
tests/Tests.h

@ -1,7 +1,12 @@
#pragma once #pragma once
#if defined(_MSC_VER) #if defined(_MSC_VER)
#if defined(DLL_EXPORT)
#define DLL_API __declspec(dllexport) #define DLL_API __declspec(dllexport)
#else
#define DLL_API __declspec(dllimport)
#endif
#ifndef STDCALL #ifndef STDCALL
#define STDCALL __stdcall #define STDCALL __stdcall

Loading…
Cancel
Save