diff --git a/build/LLVM.lua b/build/LLVM.lua index 373e41ee..49e7db69 100644 --- a/build/LLVM.lua +++ b/build/LLVM.lua @@ -42,6 +42,7 @@ function SetupLLVMIncludes() includedirs { path.join(LLVMRootDirDebug, "include"), + path.join(LLVMRootDirDebug, "lld/include"), path.join(LLVMRootDirDebug, "clang/include"), path.join(LLVMRootDirDebug, "clang/lib"), path.join(LLVMRootDirDebug, "build/include"), @@ -52,6 +53,7 @@ function SetupLLVMIncludes() includedirs { path.join(LLVMRootDirRelease, "include"), + path.join(LLVMRootDirRelease, "lld/include"), path.join(LLVMRootDirRelease, "clang/include"), path.join(LLVMRootDirRelease, "clang/lib"), path.join(LLVMRootDirRelease, "build/include"), @@ -62,6 +64,7 @@ function SetupLLVMIncludes() includedirs { path.join(LLVMRootDir, "include"), + path.join(LLVMRootDir, "lld/include"), path.join(LLVMRootDir, "clang/include"), path.join(LLVMRootDir, "clang/lib"), path.join(LLVMBuildDir, "include"), @@ -196,7 +199,17 @@ function SetupLLVMLibs() "LLVMBinaryFormat", "LLVMSupport", "LLVMDemangle", - "LLVMHelloNew" + "LLVMHelloNew", + "lldCommon", + "lldCore", + "lldCOFF", + "lldMinGW", + "lldELF", + "lldDriver", + "lldReaderWriter", + "lldYAML", + "lldMachO", + "lldMachO2" } filter(c) diff --git a/src/CppParser/Bindings/CLI/CppParser.cpp b/src/CppParser/Bindings/CLI/CppParser.cpp index cbbf19a4..f7252aad 100644 --- a/src/CppParser/Bindings/CLI/CppParser.cpp +++ b/src/CppParser/Bindings/CLI/CppParser.cpp @@ -1018,6 +1018,16 @@ CppSharp::Parser::ParserResult^ CppSharp::Parser::ClangParser::ParseLibrary(CppS return (__ret == nullptr) ? nullptr : gcnew ::CppSharp::Parser::ParserResult((::CppSharp::CppParser::ParserResult*)__ret); } +CppSharp::Parser::ParserResult^ CppSharp::Parser::ClangParser::Build(CppSharp::Parser::CppParserOptions^ Opts, CppSharp::Parser::LinkerOptions^ LinkerOptions, System::String^ File, bool Last) +{ + auto __arg0 = (::CppSharp::CppParser::CppParserOptions*)Opts->NativePtr; + auto __arg1 = (::CppSharp::CppParser::LinkerOptions*)LinkerOptions->NativePtr; + auto __arg2 = clix::marshalString(File); + auto __ret = ::CppSharp::CppParser::ClangParser::Build(__arg0, __arg1, __arg2, Last); + if (__ret == nullptr) return nullptr; + return (__ret == nullptr) ? nullptr : gcnew ::CppSharp::Parser::ParserResult((::CppSharp::CppParser::ParserResult*)__ret); +} + CppSharp::Parser::ClangParser::ClangParser() { __ownsNativeInstance = true; diff --git a/src/CppParser/Bindings/CLI/CppParser.h b/src/CppParser/Bindings/CLI/CppParser.h index 12a6e641..c418f685 100644 --- a/src/CppParser/Bindings/CLI/CppParser.h +++ b/src/CppParser/Bindings/CLI/CppParser.h @@ -506,6 +506,8 @@ namespace CppSharp static CppSharp::Parser::ParserResult^ ParseLibrary(CppSharp::Parser::LinkerOptions^ Opts); + static CppSharp::Parser::ParserResult^ Build(CppSharp::Parser::CppParserOptions^ Opts, CppSharp::Parser::LinkerOptions^ LinkerOptions, System::String^ File, bool Last); + protected: bool __ownsNativeInstance; diff --git a/src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/CppSharp.CppParser.cs b/src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/CppSharp.CppParser.cs index 597e8d9c..6a74c0e4 100644 --- a/src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/CppSharp.CppParser.cs +++ b/src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/CppSharp.CppParser.cs @@ -40245,6 +40245,9 @@ namespace CppSharp [SuppressUnmanagedCodeSecurity, DllImport("CppSharp.CppParser", EntryPoint = "_ZN8CppSharp9CppParser11ClangParser12ParseLibraryEPNS0_13LinkerOptionsE", CallingConvention = __CallingConvention.Cdecl)] internal static extern __IntPtr ParseLibrary(__IntPtr Opts); + + [SuppressUnmanagedCodeSecurity, DllImport("CppSharp.CppParser", EntryPoint = "_ZN8CppSharp9CppParser11ClangParser5BuildEPNS0_16CppParserOptionsEPKNS0_13LinkerOptionsERKNSt3__112basic_stringIcNS7_11char_traitsIcEENS7_9allocatorIcEEEEb", CallingConvention = __CallingConvention.Cdecl)] + internal static extern __IntPtr Build(__IntPtr Opts, __IntPtr LinkerOptions, __IntPtr File, bool Last); } public __IntPtr __Instance { get; protected set; } @@ -40341,6 +40344,19 @@ namespace CppSharp var __result0 = global::CppSharp.Parser.ParserResult.__GetOrCreateInstance(__ret, false); return __result0; } + + public static global::CppSharp.Parser.ParserResult Build(global::CppSharp.Parser.CppParserOptions Opts, global::CppSharp.Parser.LinkerOptions LinkerOptions, string File, bool Last) + { + var __arg0 = Opts is null ? __IntPtr.Zero : Opts.__Instance; + var __arg1 = LinkerOptions is null ? __IntPtr.Zero : LinkerOptions.__Instance; + var __basicString2 = new global::Std.BasicString, global::Std.Allocator>(); + global::Std.BasicStringExtensions.Assign(__basicString2, File); + var __arg2 = __basicString2.__Instance; + var __ret = __Internal.Build(__arg0, __arg1, __arg2, Last); + __basicString2.Dispose(); + var __result0 = global::CppSharp.Parser.ParserResult.__GetOrCreateInstance(__ret, false); + return __result0; + } } } } diff --git a/src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/CppSharp.CppParser.cs b/src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/CppSharp.CppParser.cs index a1510c8b..1f90cc3d 100644 --- a/src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/CppSharp.CppParser.cs +++ b/src/CppParser/Bindings/CSharp/i686-pc-win32-msvc/CppSharp.CppParser.cs @@ -40256,6 +40256,9 @@ namespace CppSharp [SuppressUnmanagedCodeSecurity, DllImport("CppSharp.CppParser.dll", EntryPoint = "?ParseLibrary@ClangParser@CppParser@CppSharp@@SAPAUParserResult@23@PAULinkerOptions@23@@Z", CallingConvention = __CallingConvention.Cdecl)] internal static extern __IntPtr ParseLibrary(__IntPtr Opts); + + [SuppressUnmanagedCodeSecurity, DllImport("CppSharp.CppParser.dll", EntryPoint = "?Build@ClangParser@CppParser@CppSharp@@SAPAUParserResult@23@PAUCppParserOptions@23@PBULinkerOptions@23@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@_N@Z", CallingConvention = __CallingConvention.Cdecl)] + internal static extern __IntPtr Build(__IntPtr Opts, __IntPtr LinkerOptions, __IntPtr File, bool Last); } public __IntPtr __Instance { get; protected set; } @@ -40352,6 +40355,19 @@ namespace CppSharp var __result0 = global::CppSharp.Parser.ParserResult.__GetOrCreateInstance(__ret, false); return __result0; } + + public static global::CppSharp.Parser.ParserResult Build(global::CppSharp.Parser.CppParserOptions Opts, global::CppSharp.Parser.LinkerOptions LinkerOptions, string File, bool Last) + { + var __arg0 = Opts is null ? __IntPtr.Zero : Opts.__Instance; + var __arg1 = LinkerOptions is null ? __IntPtr.Zero : LinkerOptions.__Instance; + var __basicString2 = new global::Std.BasicString, global::Std.Allocator>(); + global::Std.BasicStringExtensions.Assign(__basicString2, File); + var __arg2 = __basicString2.__Instance; + var __ret = __Internal.Build(__arg0, __arg1, __arg2, Last); + __basicString2.Dispose(); + var __result0 = global::CppSharp.Parser.ParserResult.__GetOrCreateInstance(__ret, false); + return __result0; + } } } } diff --git a/src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/CppSharp.CppParser.cs b/src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/CppSharp.CppParser.cs index 5ea08cf4..7961ebaf 100644 --- a/src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/CppSharp.CppParser.cs +++ b/src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/CppSharp.CppParser.cs @@ -40244,6 +40244,9 @@ namespace CppSharp [SuppressUnmanagedCodeSecurity, DllImport("CppSharp.CppParser", EntryPoint = "_ZN8CppSharp9CppParser11ClangParser12ParseLibraryEPNS0_13LinkerOptionsE", CallingConvention = __CallingConvention.Cdecl)] internal static extern __IntPtr ParseLibrary(__IntPtr Opts); + + [SuppressUnmanagedCodeSecurity, DllImport("CppSharp.CppParser", EntryPoint = "_ZN8CppSharp9CppParser11ClangParser5BuildEPNS0_16CppParserOptionsEPKNS0_13LinkerOptionsERKNSt3__112basic_stringIcNS7_11char_traitsIcEENS7_9allocatorIcEEEEb", CallingConvention = __CallingConvention.Cdecl)] + internal static extern __IntPtr Build(__IntPtr Opts, __IntPtr LinkerOptions, __IntPtr File, bool Last); } public __IntPtr __Instance { get; protected set; } @@ -40340,6 +40343,19 @@ namespace CppSharp var __result0 = global::CppSharp.Parser.ParserResult.__GetOrCreateInstance(__ret, false); return __result0; } + + public static global::CppSharp.Parser.ParserResult Build(global::CppSharp.Parser.CppParserOptions Opts, global::CppSharp.Parser.LinkerOptions LinkerOptions, string File, bool Last) + { + var __arg0 = Opts is null ? __IntPtr.Zero : Opts.__Instance; + var __arg1 = LinkerOptions is null ? __IntPtr.Zero : LinkerOptions.__Instance; + var __basicString2 = new global::Std.BasicString, global::Std.Allocator>(); + global::Std.BasicStringExtensions.Assign(__basicString2, File); + var __arg2 = __basicString2.__Instance; + var __ret = __Internal.Build(__arg0, __arg1, __arg2, Last); + __basicString2.Dispose(); + var __result0 = global::CppSharp.Parser.ParserResult.__GetOrCreateInstance(__ret, false); + return __result0; + } } } } diff --git a/src/CppParser/Bindings/CSharp/x86_64-linux-gnu-cxx11abi/CppSharp.CppParser.cs b/src/CppParser/Bindings/CSharp/x86_64-linux-gnu-cxx11abi/CppSharp.CppParser.cs index 09c37787..e66c757a 100644 --- a/src/CppParser/Bindings/CSharp/x86_64-linux-gnu-cxx11abi/CppSharp.CppParser.cs +++ b/src/CppParser/Bindings/CSharp/x86_64-linux-gnu-cxx11abi/CppSharp.CppParser.cs @@ -40244,6 +40244,9 @@ namespace CppSharp [SuppressUnmanagedCodeSecurity, DllImport("CppSharp.CppParser", EntryPoint = "_ZN8CppSharp9CppParser11ClangParser12ParseLibraryEPNS0_13LinkerOptionsE", CallingConvention = __CallingConvention.Cdecl)] internal static extern __IntPtr ParseLibrary(__IntPtr Opts); + + [SuppressUnmanagedCodeSecurity, DllImport("CppSharp.CppParser", EntryPoint = "_ZN8CppSharp9CppParser11ClangParser5BuildEPNS0_16CppParserOptionsEPKNS0_13LinkerOptionsERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEb", CallingConvention = __CallingConvention.Cdecl)] + internal static extern __IntPtr Build(__IntPtr Opts, __IntPtr LinkerOptions, __IntPtr File, bool Last); } public __IntPtr __Instance { get; protected set; } @@ -40340,6 +40343,19 @@ namespace CppSharp var __result0 = global::CppSharp.Parser.ParserResult.__GetOrCreateInstance(__ret, false); return __result0; } + + public static global::CppSharp.Parser.ParserResult Build(global::CppSharp.Parser.CppParserOptions Opts, global::CppSharp.Parser.LinkerOptions LinkerOptions, string File, bool Last) + { + var __arg0 = Opts is null ? __IntPtr.Zero : Opts.__Instance; + var __arg1 = LinkerOptions is null ? __IntPtr.Zero : LinkerOptions.__Instance; + var __basicString2 = new global::Std.BasicString, global::Std.Allocator>(); + global::Std.BasicStringExtensions.Assign(__basicString2, File); + var __arg2 = __basicString2.__Instance; + var __ret = __Internal.Build(__arg0, __arg1, __arg2, Last); + __basicString2.Dispose(); + var __result0 = global::CppSharp.Parser.ParserResult.__GetOrCreateInstance(__ret, false); + return __result0; + } } } } diff --git a/src/CppParser/Bindings/CSharp/x86_64-linux-gnu/CppSharp.CppParser.cs b/src/CppParser/Bindings/CSharp/x86_64-linux-gnu/CppSharp.CppParser.cs index 667d54c5..a6fe6b26 100644 --- a/src/CppParser/Bindings/CSharp/x86_64-linux-gnu/CppSharp.CppParser.cs +++ b/src/CppParser/Bindings/CSharp/x86_64-linux-gnu/CppSharp.CppParser.cs @@ -40244,6 +40244,9 @@ namespace CppSharp [SuppressUnmanagedCodeSecurity, DllImport("CppSharp.CppParser", EntryPoint = "_ZN8CppSharp9CppParser11ClangParser12ParseLibraryEPNS0_13LinkerOptionsE", CallingConvention = __CallingConvention.Cdecl)] internal static extern __IntPtr ParseLibrary(__IntPtr Opts); + + [SuppressUnmanagedCodeSecurity, DllImport("CppSharp.CppParser", EntryPoint = "_ZN8CppSharp9CppParser11ClangParser5BuildEPNS0_16CppParserOptionsEPKNS0_13LinkerOptionsERKSsb", CallingConvention = __CallingConvention.Cdecl)] + internal static extern __IntPtr Build(__IntPtr Opts, __IntPtr LinkerOptions, __IntPtr File, bool Last); } public __IntPtr __Instance { get; protected set; } @@ -40340,6 +40343,19 @@ namespace CppSharp var __result0 = global::CppSharp.Parser.ParserResult.__GetOrCreateInstance(__ret, false); return __result0; } + + public static global::CppSharp.Parser.ParserResult Build(global::CppSharp.Parser.CppParserOptions Opts, global::CppSharp.Parser.LinkerOptions LinkerOptions, string File, bool Last) + { + var __arg0 = Opts is null ? __IntPtr.Zero : Opts.__Instance; + var __arg1 = LinkerOptions is null ? __IntPtr.Zero : LinkerOptions.__Instance; + var __basicString2 = new global::Std.BasicString, global::Std.Allocator>(); + global::Std.BasicStringExtensions.Assign(__basicString2, File); + var __arg2 = __basicString2.__Instance; + var __ret = __Internal.Build(__arg0, __arg1, __arg2, Last); + __basicString2.Dispose(); + var __result0 = global::CppSharp.Parser.ParserResult.__GetOrCreateInstance(__ret, false); + return __result0; + } } } } diff --git a/src/CppParser/Bindings/CSharp/x86_64-pc-win32-msvc/CppSharp.CppParser.cs b/src/CppParser/Bindings/CSharp/x86_64-pc-win32-msvc/CppSharp.CppParser.cs index 0993cc45..eb5d3905 100644 --- a/src/CppParser/Bindings/CSharp/x86_64-pc-win32-msvc/CppSharp.CppParser.cs +++ b/src/CppParser/Bindings/CSharp/x86_64-pc-win32-msvc/CppSharp.CppParser.cs @@ -40301,6 +40301,9 @@ namespace CppSharp [SuppressUnmanagedCodeSecurity, DllImport("CppSharp.CppParser.dll", EntryPoint = "?ParseLibrary@ClangParser@CppParser@CppSharp@@SAPEAUParserResult@23@PEAULinkerOptions@23@@Z", CallingConvention = __CallingConvention.Cdecl)] internal static extern __IntPtr ParseLibrary(__IntPtr Opts); + + [SuppressUnmanagedCodeSecurity, DllImport("CppSharp.CppParser.dll", EntryPoint = "?Build@ClangParser@CppParser@CppSharp@@SAPEAUParserResult@23@PEAUCppParserOptions@23@PEBULinkerOptions@23@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@_N@Z", CallingConvention = __CallingConvention.Cdecl)] + internal static extern __IntPtr Build(__IntPtr Opts, __IntPtr LinkerOptions, __IntPtr File, bool Last); } public __IntPtr __Instance { get; protected set; } @@ -40397,6 +40400,19 @@ namespace CppSharp var __result0 = global::CppSharp.Parser.ParserResult.__GetOrCreateInstance(__ret, false); return __result0; } + + public static global::CppSharp.Parser.ParserResult Build(global::CppSharp.Parser.CppParserOptions Opts, global::CppSharp.Parser.LinkerOptions LinkerOptions, string File, bool Last) + { + var __arg0 = Opts is null ? __IntPtr.Zero : Opts.__Instance; + var __arg1 = LinkerOptions is null ? __IntPtr.Zero : LinkerOptions.__Instance; + var __basicString2 = new global::Std.BasicString, global::Std.Allocator>(); + global::Std.BasicStringExtensions.Assign(__basicString2, File); + var __arg2 = __basicString2.__Instance; + var __ret = __Internal.Build(__arg0, __arg1, __arg2, Last); + __basicString2.Dispose(); + var __result0 = global::CppSharp.Parser.ParserResult.__GetOrCreateInstance(__ret, false); + return __result0; + } } } } diff --git a/src/CppParser/CppParser.h b/src/CppParser/CppParser.h index 9f60df44..7edf47c6 100644 --- a/src/CppParser/CppParser.h +++ b/src/CppParser/CppParser.h @@ -120,6 +120,8 @@ public: static ParserResult* ParseHeader(CppParserOptions* Opts); static ParserResult* ParseLibrary(LinkerOptions* Opts); + static ParserResult* Build(CppParserOptions* Opts, + const LinkerOptions* LinkerOptions, const std::string& File, bool Last); }; } } \ No newline at end of file diff --git a/src/CppParser/Link.cpp b/src/CppParser/Link.cpp new file mode 100644 index 00000000..d97d831d --- /dev/null +++ b/src/CppParser/Link.cpp @@ -0,0 +1,290 @@ +/************************************************************************ +* +* CppSharp +* Licensed under the simplified BSD license. All rights reserved. +* +************************************************************************/ + +#include "CppParser.h" +#include "Parser.h" +#include +#include +#include + +using namespace CppSharp::CppParser; + +void Parser::Link(const std::string& File, const LinkerOptions* LinkerOptions) +{ + std::vector args; + llvm::StringRef Dir(llvm::sys::path::parent_path(File)); + llvm::StringRef Stem = llvm::sys::path::stem(File); + + const llvm::Triple Triple = c->getTarget().getTriple(); + switch (Triple.getOS()) + { + case llvm::Triple::OSType::Win32: + args.push_back("-subsystem:windows"); + switch (Triple.getEnvironment()) + { + case llvm::Triple::EnvironmentType::MSVC: + LinkMSVC(LinkerOptions, args, Dir, Stem); + break; + + case llvm::Triple::EnvironmentType::GNU: + LinkMinGW(LinkerOptions, args, Dir, Stem); + break; + + default: + break; + } + break; + + case llvm::Triple::OSType::Linux: + LinkELF(LinkerOptions, args, Dir, Stem); + break; + + case llvm::Triple::OSType::Darwin: + case llvm::Triple::OSType::MacOSX: + LinkMachO(LinkerOptions, args, Dir, Stem); + break; + + default: + break; + } +} + +void Parser::LinkMSVC(const LinkerOptions* LinkerOptions, + std::vector& args, const llvm::StringRef& Dir, llvm::StringRef& Stem) +{ +#ifdef _WIN32 + using namespace llvm; + using namespace clang; + + const Triple& Triple = c->getTarget().getTriple(); + driver::Driver D("", Triple.str(), c->getDiagnostics()); + driver::toolchains::MSVCToolChain TC(D, Triple, opt::InputArgList(0, 0)); + + std::vector LibraryPaths; + LibraryPaths.push_back("-libpath:" + TC.getSubDirectoryPath( + clang::driver::toolchains::MSVCToolChain::SubDirectoryType::Lib)); + std::string CRTPath; + if (TC.getUniversalCRTLibraryPath(CRTPath)) + LibraryPaths.push_back("-libpath:" + CRTPath); + std::string WinSDKPath; + if (TC.getWindowsSDKLibraryPath(WinSDKPath)) + LibraryPaths.push_back("-libpath:" + WinSDKPath); + for (const auto& LibraryDir : LinkerOptions->LibraryDirs) + LibraryPaths.push_back("-libpath:" + LibraryDir); + for (const auto& LibraryPath : LibraryPaths) + args.push_back(LibraryPath.data()); + + args.push_back("-dll"); + args.push_back("libcmt.lib"); + + std::vector Libraries; + for (const auto& Library : LinkerOptions->Libraries) + Libraries.push_back(Library + ".lib"); + for (const auto& Library : Libraries) + args.push_back(Library.data()); + + args.push_back(c->getFrontendOpts().OutputFile.data()); + SmallString<1024> Output(Dir); + sys::path::append(Output, Stem + ".dll"); + std::string Out("-out:" + std::string(Output)); + args.push_back(Out.data()); + + lld::coff::link(args, false, outs(), errs()); +#endif +} + +void Parser::LinkMinGW(const LinkerOptions* LinkerOptions, + std::vector& args, const llvm::StringRef& Dir, llvm::StringRef& Stem) +{ +#ifdef _WIN32 + using namespace llvm; + using namespace clang; + + args.push_back("-lldmingw"); + + const Triple& Triple = c->getTarget().getTriple(); + driver::Driver D("", Triple.str(), c->getDiagnostics()); + driver::toolchains::MSVCToolChain TC(D, Triple, opt::InputArgList(0, 0)); + + std::vector LibraryPaths; + LibraryPaths.push_back("-libpath:" + TC.getSubDirectoryPath( + clang::driver::toolchains::MSVCToolChain::SubDirectoryType::Lib)); + std::string CRTPath; + if (TC.getUniversalCRTLibraryPath(CRTPath)) + LibraryPaths.push_back("-libpath:" + CRTPath); + std::string WinSDKPath; + if (TC.getWindowsSDKLibraryPath(WinSDKPath)) + LibraryPaths.push_back("-libpath:" + WinSDKPath); + for (const auto& LibraryDir : LinkerOptions->LibraryDirs) + LibraryPaths.push_back("-libpath:" + LibraryDir); + for (const auto& LibraryPath : LibraryPaths) + args.push_back(LibraryPath.data()); + + args.push_back("-dll"); + args.push_back("libcmt.lib"); + args.push_back("libstdc++.dll.a"); + + // TODO: MinGW has an additional library dir for its specific C++ STD (above); hard-coded now for testing but needs fixing + args.push_back("-libpath:C:\\Qt\\Tools\\mingw730_64\\lib\\gcc\\x86_64-w64-mingw32\\7.3.0"); + // std::string LinkingDir("-L" + Dir.str()); + + std::vector Libraries; + for (const auto& Library : LinkerOptions->Libraries) + // TODO: libs are a problem with MinGW; first, I need the lib dir as well as the bin dir given now; second, the libs are lib*.a, not *.lib; + // the -l syntax should handle it but calling MinGW directly hangs the process; still, it's highly desirable to use MinGW because it does much of the work, such as this conversion from lib*.a + // on the other hand, keeping the MSVC allows me to reuse almost all of the code from LinkMSVC + Libraries.push_back("lib" + Library + ".a"); + for (const auto& Library : Libraries) + args.push_back(Library.data()); + + args.push_back(c->getFrontendOpts().OutputFile.data()); + SmallString<1024> Output(Dir); + sys::path::append(Output, Stem + ".dll"); + std::string Out("-out:" + std::string(Output)); + args.push_back(Out.data()); + + lld::coff::link(args, false, outs(), errs()); +#endif +//#ifdef _WIN32 +// using namespace llvm; +// using namespace clang; +// +// //g++ -c -fno-keep-inline-dllexport -Wa,-mbig-obj -O2 -std=gnu++11 -Wall -W -Wextra -fexceptions -mthreads -DUNICODE -D_UNICODE -DWIN32 -DMINGW_HAS_SECURE_API=1 -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I. +// // -IC:\Qt\5.12.5\mingw73_64\include -IC:\Qt\5.12.5\mingw73_64\include\QtGui -IC:\Qt\5.12.5\mingw73_64\include\QtANGLE -IC:\Qt\5.12.5\mingw73_64\include\QtCore -Irelease +// // -I/include -IC:\Qt\5.12.5\mingw73_64\mkspecs\win32-g++ -o release\QtCore-symbols.o QtCore-symbols.cpp +// +// const Triple& Triple = c->getTarget().getTriple(); +// driver::Driver D("", Triple.str(), c->getDiagnostics()); +// driver::toolchains::MSVCToolChain TC(D, Triple, opt::InputArgList(0, 0)); +// +// std::vector LibraryPaths; +// LibraryPaths.push_back("-L" + TC.getSubDirectoryPath( +// clang::driver::toolchains::MSVCToolChain::SubDirectoryType::Lib)); +// std::string CRTPath; +// if (TC.getUniversalCRTLibraryPath(CRTPath)) +// LibraryPaths.push_back("-L" + CRTPath); +// std::string WinSDKPath; +// if (TC.getWindowsSDKLibraryPath(WinSDKPath)) +// LibraryPaths.push_back("-L" + WinSDKPath); +// for (const auto& LibraryDir : LinkerOptions->LibraryDirs) +// LibraryPaths.push_back("-L" + LibraryDir); +// for (const auto& LibraryPath : LibraryPaths) +// args.push_back(LibraryPath.data()); +// +// args.push_back("libcmt.lib"); +// args.push_back("-lstdc++"); +// args.push_back("--shared"); +// +// args.push_back("-LC:\\Qt\\Tools\\mingw730_64\\lib\\gcc\\x86_64-w64-mingw32\\7.3.0"); +// std::string LinkingDir("-L" + Dir.str()); +// args.push_back(LinkingDir.data()); +// std::vector LibraryDirs; +// for (const auto& LibraryDir : LinkerOptions->LibraryDirs) +// LibraryDirs.push_back("-L" + LibraryDir); +// for (const auto& LibraryDir : LibraryDirs) +// args.push_back(LibraryDir.data()); +// +// std::vector Libraries; +// for (const auto& Library : LinkerOptions->Libraries) +// Libraries.push_back("-l" + Library); +// for (const auto& Library : Libraries) +// args.push_back(Library.data()); +// +// args.push_back(c->getFrontendOpts().OutputFile.data()); +// +// args.push_back("-o"); +// SmallString<1024> Output(Dir); +// sys::path::append(Output, Stem + ".dll"); +// std::string Out(Output); +// args.push_back(Out.data()); +// +// lld::mingw::link(args, false, outs(), errs()); +//#endif +} + +void Parser::LinkELF(const LinkerOptions* LinkerOptions, + std::vector& args, + llvm::StringRef& Dir, llvm::StringRef& Stem) +{ +#ifdef __linux__ + using namespace llvm; + + args.push_back("-flavor gnu"); + args.push_back("-L/usr/lib/x86_64-linux-gnu"); + args.push_back("-lc"); + args.push_back("--shared"); + args.push_back("-rpath"); + args.push_back("."); + + std::string LinkingDir("-L" + Dir.str()); + args.push_back(LinkingDir.data()); + std::vector LibraryDirs; + for (const auto& LibraryDir : LinkerOptions->LibraryDirs) + LibraryDirs.push_back("-L" + LibraryDir); + for (const auto& LibraryDir : LibraryDirs) + args.push_back(LibraryDir.data()); + + std::vector Libraries; + for (const auto& Library : LinkerOptions->Libraries) + Libraries.push_back("-l" + Library); + for (const auto& Library : Libraries) + args.push_back(Library.data()); + + args.push_back(c->getFrontendOpts().OutputFile.data()); + + args.push_back("-o"); + SmallString<1024> Output(Dir); + sys::path::append(Output, "lib" + Stem + ".so"); + std::string Out(Output); + args.push_back(Out.data()); + + lld::elf::link(args, false, outs(), errs()); +#endif +} + +void Parser::LinkMachO(const LinkerOptions* LinkerOptions, + std::vector& args, + llvm::StringRef& Dir, llvm::StringRef& Stem) +{ +#ifdef __APPLE__ + using namespace llvm; + + args.push_back("-flavor darwinnew"); + args.push_back("-lc++"); + args.push_back("-lSystem"); + args.push_back("-dylib"); + args.push_back("-sdk_version"); + args.push_back("10.12.0"); + args.push_back("-L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib"); + args.push_back("-rpath"); + args.push_back("."); + + std::string LinkingDir("-L" + Dir.str()); + args.push_back(LinkingDir.data()); + std::vector LibraryDirs; + for (const auto& LibraryDir : LinkerOptions->LibraryDirs) + LibraryDirs.push_back("-L" + LibraryDir); + for (const auto& LibraryDir : LibraryDirs) + args.push_back(LibraryDir.data()); + + std::vector Libraries; + for (const auto& Library : LinkerOptions->Libraries) + Libraries.push_back("-l" + Library); + for (const auto& Library : Libraries) + args.push_back(Library.data()); + + args.push_back(c->getFrontendOpts().OutputFile.data()); + + args.push_back("-o"); + SmallString<1024> Output(Dir); + sys::path::append(Output, "lib" + Stem + ".dylib"); + std::string Out(Output); + args.push_back(Out.data()); + + lld::mach_o::link(args, false, outs(), errs()); +#endif +} \ No newline at end of file diff --git a/src/CppParser/Parser.cpp b/src/CppParser/Parser.cpp index c70bd444..5998e7f3 100644 --- a/src/CppParser/Parser.cpp +++ b/src/CppParser/Parser.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -245,6 +246,8 @@ void Parser::Setup() std::vector args; args.push_back("-cc1"); + args.push_back("-flto"); + args.push_back("-O3"); for (unsigned I = 0, E = opts->Arguments.size(); I != E; ++I) { @@ -4622,6 +4625,22 @@ ParserResult* Parser::ParseLibrary(const LinkerOptions* Opts) return res; } +ParserResult* Parser::Build(const LinkerOptions* LinkerOptions, const std::string& File, bool Last) +{ + ParserResult* error = Compile(File); + if (error) + return error; + + Link(File, LinkerOptions); + + if (Last) + llvm::llvm_shutdown(); + + auto res = new ParserResult(); + HandleDiagnostics(res); + return res; +} + ParserResult* ClangParser::ParseHeader(CppParserOptions* Opts) { if (!Opts) @@ -4661,6 +4680,45 @@ ParserResult* ClangParser::ParseLibrary(LinkerOptions* Opts) return Parser::ParseLibrary(Opts); } +ParserResult* ClangParser::Build(CppParserOptions* Opts, + const LinkerOptions* LinkerOptions, const std::string& File, bool Last) +{ + if (!Opts) + return 0; + + Parser Parser(Opts); + return Parser.Build(LinkerOptions, File, Last); +} + +ParserResult* Parser::Compile(const std::string& File) +{ + llvm::InitializeAllAsmPrinters(); + llvm::StringRef Stem = llvm::sys::path::stem(File); + Setup(); + + c->getDiagnostics().setClient(new ::DiagnosticConsumer()); + + c->getFrontendOpts().Inputs.clear(); + c->getFrontendOpts().Inputs.push_back(clang::FrontendInputFile(File, clang::Language::CXX)); + + const llvm::Triple Triple = c->getTarget().getTriple(); + llvm::StringRef Dir(llvm::sys::path::parent_path(File)); + llvm::SmallString<1024> Object(Dir); + llvm::sys::path::append(Object, + (Triple.isOSWindows() ? "" : "lib") + Stem + ".o"); + c->getFrontendOpts().OutputFile = std::string(Object); + + llvm::LLVMContext context; + auto action = std::make_unique(&context); + if (!c->ExecuteAction(*action)) + { + auto res = new ParserResult(); + HandleDiagnostics(res); + return res; + } + return 0; +} + ParserTargetInfo* Parser::GetTargetInfo() { auto parserTargetInfo = new ParserTargetInfo(); diff --git a/src/CppParser/Parser.h b/src/CppParser/Parser.h index b865be0b..36c490d6 100644 --- a/src/CppParser/Parser.h +++ b/src/CppParser/Parser.h @@ -55,7 +55,7 @@ public: void Setup(); ParserResult* Parse(const std::vector& SourceFiles); static ParserResult* ParseLibrary(const LinkerOptions* Opts); - + ParserResult* Build(const LinkerOptions* LinkerOptions, const std::string& File, bool Last); void WalkAST(clang::TranslationUnitDecl* TU); void HandleDeclaration(const clang::Decl* D, Declaration* Decl); CppParserOptions* opts; @@ -168,6 +168,17 @@ private: llvm::object::ObjectFile* ObjectFile, std::vector& NativeLibs); ParserTargetInfo* GetTargetInfo(); + ParserResult* Compile(const std::string& File); + void Link(const std::string& File, const LinkerOptions* LinkerOptions); + void LinkMSVC(const LinkerOptions* LinkerOptions, std::vector& args, + const llvm::StringRef& Dir, llvm::StringRef& Stem); + void LinkMinGW(const LinkerOptions* LinkerOptions, std::vector& args, + const llvm::StringRef& Dir, llvm::StringRef& Stem); + void LinkELF(const LinkerOptions* LinkerOptions, std::vector& args, + llvm::StringRef& Dir, llvm::StringRef& Stem); + void LinkMachO(const LinkerOptions* LinkerOptions, std::vector& args, + llvm::StringRef& Dir, llvm::StringRef& Stem); + int index; std::unique_ptr c; llvm::LLVMContext LLVMCtx; diff --git a/src/Generator.Tests/ASTTestFixture.cs b/src/Generator.Tests/ASTTestFixture.cs index 2428ddcc..2bb37f4b 100644 --- a/src/Generator.Tests/ASTTestFixture.cs +++ b/src/Generator.Tests/ASTTestFixture.cs @@ -15,18 +15,14 @@ namespace CppSharp.Generator.Tests protected void ParseLibrary(params string[] files) { var options = new DriverOptions { GeneratorKind = GeneratorKind.CSharp }; - var parserOptions = new ParserOptions(); - - var testsPath = GeneratorTest.GetTestsDirectory("Native"); - parserOptions.AddIncludeDirs(testsPath); - parserOptions.SkipPrivateDeclarations = true; var module = options.AddModule("Test"); + module.IncludeDirs.Add(GeneratorTest.GetTestsDirectory("Native")); module.Headers.AddRange(files); Driver = new Driver(options) { - ParserOptions = parserOptions + ParserOptions = new ParserOptions { SkipPrivateDeclarations = true } }; Driver.Setup(); diff --git a/src/Generator.Tests/GeneratorTest.cs b/src/Generator.Tests/GeneratorTest.cs index a400bc97..70d647f7 100644 --- a/src/Generator.Tests/GeneratorTest.cs +++ b/src/Generator.Tests/GeneratorTest.cs @@ -27,8 +27,8 @@ namespace CppSharp.Utils options.OutputDir = Path.Combine(GetOutputDirectory(), "build", "gen", name); options.Quiet = true; options.GenerateDebugOutput = true; + options.CheckSymbols = true; var testModule = options.AddModule(name); - testModule.SharedLibraryName = $"{name}.Native"; Diagnostics.Message(""); Diagnostics.Message("Generating bindings for {0} ({1})", @@ -40,6 +40,8 @@ namespace CppSharp.Utils var path = Path.GetFullPath(GetTestsDirectory(name)); testModule.IncludeDirs.Add(path); + testModule.LibraryDirs.Add(options.OutputDir); + testModule.Libraries.Add($"{name}.Native"); Diagnostics.Message("Looking for tests in: {0}", path); var files = Directory.EnumerateFiles(path, "*.h"); diff --git a/src/Generator/Passes/GenerateSymbolsPass.cs b/src/Generator/Passes/GenerateSymbolsPass.cs index b23fb5c0..95ebc4fb 100644 --- a/src/Generator/Passes/GenerateSymbolsPass.cs +++ b/src/Generator/Passes/GenerateSymbolsPass.cs @@ -42,11 +42,44 @@ namespace CppSharp.Passes var e = new SymbolsCodeEventArgs(module); SymbolsCodeGenerated?.Invoke(this, e); - if (string.IsNullOrEmpty(e.CustomCompiler)) - RemainingCompilationTasks--; - else + if (!string.IsNullOrEmpty(e.CustomCompiler)) + { InvokeCompiler(e.CustomCompiler, e.CompilerArguments, e.OutputDir, module); + continue; + } + + if (Options.CheckSymbols && (module == Options.SystemModule || + // if the user's provided no libraries, he only wants to generate code + (module.LibraryDirs.Count > 0 && module.Libraries.Count > 0))) + { + using (var linkerOptions = new LinkerOptions()) + { + foreach (var libraryDir in module.Dependencies.Union( + new[] { module }).SelectMany(d => d.LibraryDirs)) + linkerOptions.AddLibraryDirs(libraryDir); + + foreach (var library in module.Dependencies.Union( + new[] { module }).SelectMany(d => d.Libraries)) + linkerOptions.AddLibraries(library); + + using (var result = Parser.ClangParser.Build( + Context.ParserOptions, linkerOptions, path, + Last: remainingCompilationTasks == 1)) + { + if (PrintDiagnostics(result)) + { + compiledLibraries[module] = new CompiledLibrary + { + OutputDir = Options.OutputDir, + Library = module.SymbolsLibraryName + }; + } + } + } + } + + RemainingCompilationTasks--; } } @@ -146,6 +179,42 @@ namespace CppSharp.Passes return symbolsCodeGenerator; } + private static bool PrintDiagnostics(ParserResult result) + { + bool success = true; + for (uint i = 0; i < result.DiagnosticsCount; i++) + { + var diag = result.GetDiagnostics(i); + switch (diag.Level) + { + case ParserDiagnosticLevel.Ignored: + case ParserDiagnosticLevel.Note: + Diagnostics.Message("{0}({1},{2}): {3}: {4}", + diag.FileName, diag.LineNumber, diag.ColumnNumber, + diag.Level.ToString().ToLower(), diag.Message); + break; + case ParserDiagnosticLevel.Warning: + Diagnostics.Warning("{0}({1},{2}): {3}: {4}", + diag.FileName, diag.LineNumber, diag.ColumnNumber, + diag.Level.ToString().ToLower(), diag.Message); + break; + case ParserDiagnosticLevel.Error: + Diagnostics.Error("{0}({1},{2}): {3}: {4}", + diag.FileName, diag.LineNumber, diag.ColumnNumber, + diag.Level.ToString().ToLower(), diag.Message); + success = false; + break; + case ParserDiagnosticLevel.Fatal: + Diagnostics.Debug("{0}({1},{2}): {3}: {4}", + diag.FileName, diag.LineNumber, diag.ColumnNumber, + diag.Level.ToString().ToLower(), diag.Message); + success = false; + break; + } + } + return success; + } + private void InvokeCompiler(string compiler, string arguments, string outputDir, Module module) { new Thread(() => diff --git a/tests/CSharp/CSharp.cpp b/tests/CSharp/CSharp.cpp index e6c17fb0..1c396a13 100644 --- a/tests/CSharp/CSharp.cpp +++ b/tests/CSharp/CSharp.cpp @@ -33,10 +33,6 @@ Foo::Foo(const Foo& other) : A(other.A), P(other.P), { } -Foo::~Foo() -{ -} - int Foo::method() { return 1; @@ -178,11 +174,6 @@ void Quux::setSetterWithDefaultOverload(Foo* value) _setterWithDefaultOverload = value; } -QColor::QColor() -{ - -} - QColor::QColor(Qt::GlobalColor color) { @@ -241,15 +232,15 @@ int Qux::type() const return 0; } -Bar::Bar(Qux qux) +Bar::Bar() : index(0) { } -Bar::Bar(Items item) +Bar::Bar(Qux qux) { } -Bar::~Bar() +Bar::Bar(Items item) { } @@ -302,21 +293,9 @@ int Bar::type() const return 1; } -ForceCreationOfInterface::ForceCreationOfInterface() -{ -} - -ForceCreationOfInterface::~ForceCreationOfInterface() -{ -} +Baz::Baz() : P(5), functionTypedef(0) {} -Baz::Baz() : P(5) {} - -Baz::Baz(Bar::Items item) -{ -} - -Baz::~Baz() +Baz::Baz(Bar::Items item) : Baz() { } @@ -363,17 +342,18 @@ int AbstractProprietor::parent() const return 0; } -AbstractProprietor::AbstractProprietor() +AbstractProprietor::AbstractProprietor() : m_value(0), m_property(0) { } -AbstractProprietor::AbstractProprietor(int i) +AbstractProprietor::AbstractProprietor(int i) : AbstractProprietor() { } Proprietor::Proprietor() : _items(Bar::Items::Item1), _itemsByValue(Bar::Items::Item1) {} -Proprietor::Proprietor(int i) : AbstractProprietor(i) +Proprietor::Proprietor(int i) : AbstractProprietor(i), + _items(Bar::Items::Item1), _itemsByValue(Bar::Items::Item1) { } @@ -510,7 +490,7 @@ TestDestructors::~TestDestructors() { Marker = 0xcafe; } int TestDestructors::Marker = 0; -TestCopyConstructorVal::TestCopyConstructorVal() +TestCopyConstructorVal::TestCopyConstructorVal() : A(0), B(0) { } @@ -520,14 +500,6 @@ TestCopyConstructorVal::TestCopyConstructorVal(const TestCopyConstructorVal& oth B = other.B; } -TestRenaming::TestRenaming() -{ -} - -TestRenaming::~TestRenaming() -{ -} - void TestRenaming::name() { } @@ -541,10 +513,6 @@ int TestRenaming::property() return 1; } -UsesPointerToEnum::UsesPointerToEnum() -{ -} - void UsesPointerToEnum::hasPointerToEnumInParam(Flags* flag) { } @@ -578,7 +546,8 @@ UntypedFlags operator|(UntypedFlags lhs, UntypedFlags rhs) return static_cast(static_cast(lhs) | static_cast(rhs)); } -QGenericArgument::QGenericArgument(const char *name, const void* data) +QGenericArgument::QGenericArgument(const char* name, const void* data) : + fixedArrayInValueType { 0 } { _name = name; } @@ -832,10 +801,6 @@ HasPureVirtualWithDefaultArg::~HasPureVirtualWithDefaultArg() { } -HasOverridesWithChangedAccessBase::HasOverridesWithChangedAccessBase() -{ -} - void HasOverridesWithChangedAccessBase::privateOverride(int i) { } @@ -884,14 +849,6 @@ AbstractWithProperty::~AbstractWithProperty() { } -HasOverriddenInManaged::HasOverriddenInManaged() -{ -} - -HasOverriddenInManaged::~HasOverriddenInManaged() -{ -} - void HasOverriddenInManaged::setOverriddenInManaged(Baz* value) { overriddenInManaged = value; @@ -1003,10 +960,6 @@ void TestNativeToManagedMap::setPropertyWithNoVirtualDtor(Bar* bar) this->bar = bar; } -CallDtorVirtually::CallDtorVirtually() -{ -} - CallDtorVirtually::~CallDtorVirtually() { Destroyed = true; @@ -1081,26 +1034,10 @@ TestParamToInterfacePass::TestParamToInterfacePass() : TestParamToInterfacePassB { } -HasProtectedVirtual::HasProtectedVirtual() -{ -} - void HasProtectedVirtual::protectedVirtual() { } -InheritanceBuffer::InheritanceBuffer() -{ -} - -InheritanceBuffer::~InheritanceBuffer() -{ -} - -InheritsProtectedVirtualFromSecondaryBase::InheritsProtectedVirtualFromSecondaryBase() -{ -} - InheritsProtectedVirtualFromSecondaryBase::~InheritsProtectedVirtualFromSecondaryBase() { } @@ -1122,18 +1059,10 @@ int TypeMappedWithOperator::operator |(int i) return 0; } -HasPropertyWithDerivedType::HasPropertyWithDerivedType() -{ -} - void HasPropertyWithDerivedType::causeRenamingError() { } -HasOverrideOfHasPropertyWithDerivedType::HasOverrideOfHasPropertyWithDerivedType() -{ -} - void HasOverrideOfHasPropertyWithDerivedType::causeRenamingError() { } @@ -1167,23 +1096,11 @@ void MultiOverloadPtrToRef::TakePrimTypePtr(int* ptr) ptr[2] = 300; } -OverrideFromIndirectSecondaryBaseBase::OverrideFromIndirectSecondaryBaseBase() -{ -} - int OverrideFromIndirectSecondaryBaseBase::property() { return 0; } -OverrideFromDirectSecondaryBase::OverrideFromDirectSecondaryBase() -{ -} - -OverrideFromIndirectSecondaryBase::OverrideFromIndirectSecondaryBase() -{ -} - int OverrideFromIndirectSecondaryBase::property() { return 1; @@ -1201,61 +1118,33 @@ void TestOutTypeInterfaces::funcTryInterfaceTypeOut(CS_OUT TestParamToInterfaceP { } -DerivesFromTemplateInstantiation::DerivesFromTemplateInstantiation() -{ -} - int PassConstantArrayRef(int(&arr)[2]) { return arr[0]; } -TestComparison::TestComparison() -{ -} - bool TestComparison::operator ==(const TestComparison& other) const { return A == other.A && B == other.B; } -OverridePropertyFromIndirectPrimaryBaseBase::OverridePropertyFromIndirectPrimaryBaseBase() -{ -} - OverridePropertyFromIndirectPrimaryBaseBase::~OverridePropertyFromIndirectPrimaryBaseBase() { } -OverridePropertyFromDirectPrimaryBase::OverridePropertyFromDirectPrimaryBase() -{ -} - void OverridePropertyFromDirectPrimaryBase::setProperty(int value) { } -OverridePropertyFromIndirectPrimaryBase::OverridePropertyFromIndirectPrimaryBase() -{ -} - int OverridePropertyFromIndirectPrimaryBase::property() { return 5; } -AbstractOverrideFromSecondaryBase::AbstractOverrideFromSecondaryBase() -{ -} - AbstractOverrideFromSecondaryBase::~AbstractOverrideFromSecondaryBase() { } -QObject::QObject() -{ -} - QObject::~QObject() { } @@ -1268,10 +1157,6 @@ QPaintDevice::QPaintDevice() : test(0) { } -QPaintDevice::~QPaintDevice() -{ -} - void QPaintDevice::changeVTableLayout() { } @@ -1281,10 +1166,6 @@ QWidget::QWidget() QApplication::instance->notify(this); } -QWidget::~QWidget() -{ -} - void QWidget::event() { QApplication::instance->notify(&child); @@ -1295,10 +1176,6 @@ QPainter::QPainter(QPaintDevice& paintDevice) paintDevice.test = 5; } -QPainter::~QPainter() -{ -} - QApplication::QApplication() { instance = this; @@ -1320,10 +1197,6 @@ char* HasSamePropertyInDerivedAbstractType::property() return 0; } -InheritsFromHasSamePropertyInDerivedAbstractType::InheritsFromHasSamePropertyInDerivedAbstractType() -{ -} - InheritsFromHasSamePropertyInDerivedAbstractType::~InheritsFromHasSamePropertyInDerivedAbstractType() { } @@ -1340,10 +1213,6 @@ MultipleInheritanceFieldOffsets::MultipleInheritanceFieldOffsets() : own(3) { } -VirtualDtorAddedInDerived::VirtualDtorAddedInDerived() -{ -} - VirtualDtorAddedInDerived::~VirtualDtorAddedInDerived() { dtorCalled = true; @@ -1456,30 +1325,14 @@ void decltypeFunctionPointer() {} void usesDecltypeFunctionPointer(funcPtr func) {} -TestString::~TestString() -{ -} - -PrimaryBaseWithAbstractWithDefaultArg::PrimaryBaseWithAbstractWithDefaultArg() -{ -} - PrimaryBaseWithAbstractWithDefaultArg::~PrimaryBaseWithAbstractWithDefaultArg() { } -SecondaryBaseWithAbstractWithDefaultArg::SecondaryBaseWithAbstractWithDefaultArg() -{ -} - SecondaryBaseWithAbstractWithDefaultArg::~SecondaryBaseWithAbstractWithDefaultArg() { } -HasSecondaryBaseWithAbstractWithDefaultArg::HasSecondaryBaseWithAbstractWithDefaultArg() -{ -} - HasSecondaryBaseWithAbstractWithDefaultArg::~HasSecondaryBaseWithAbstractWithDefaultArg() { } @@ -1492,28 +1345,16 @@ void HasSecondaryBaseWithAbstractWithDefaultArg::abstractWithNoDefaultArg(const { } -MissingObjectOnVirtualCallSecondaryBase::MissingObjectOnVirtualCallSecondaryBase() -{ -} - int MissingObjectOnVirtualCallSecondaryBase::f() { return 5; } -MissingObjectOnVirtualCall::MissingObjectOnVirtualCall() -{ -} - int MissingObjectOnVirtualCall::f() { return 15; } -HasMissingObjectOnVirtualCall::HasMissingObjectOnVirtualCall() -{ -} - int HasMissingObjectOnVirtualCall::makeMissingObjectOnVirtualCall() { return stackOverflowOnVirtualCall->f(); @@ -1560,26 +1401,10 @@ int ImplementsAbstractsFromPrimaryAndSecondary::abstractReturnsFieldInSecondaryB return field + 2; } -HasBaseSetter::HasBaseSetter() -{ -} - -HasBaseSetter::~HasBaseSetter() -{ -} - void HasBaseSetter::setBaseSetter(int value) { } -HasGetterAndOverriddenSetter::HasGetterAndOverriddenSetter() -{ -} - -HasGetterAndOverriddenSetter::~HasGetterAndOverriddenSetter() -{ -} - int HasGetterAndOverriddenSetter::baseSetter() { return field; @@ -1638,10 +1463,6 @@ ComplexArrayElement::ComplexArrayElement() : BoolField(false), IntField(0), Floa { } -HasComplexArray::HasComplexArray() -{ -} - TestIndexedProperties::TestIndexedProperties() : field(0) { } @@ -1677,14 +1498,6 @@ void InlineNamespace::FunctionInsideInlineNamespace() { } -TestArrays::TestArrays() -{ -} - -TestArrays::~TestArrays() -{ -} - int TestArrays::takeArrays(Foo* arrayOfPointersToObjects[], int arrayOfPrimitives[], Foo arrayOfObjects[]) const { return arrayOfPointersToObjects[0]->A + arrayOfPointersToObjects[1]->A + @@ -1736,30 +1549,14 @@ int TestArrays::virtualTakeArrays(Foo *fixedArrayOfPointersToObjects[], int fixe return takeArrays(fixedArrayOfPointersToObjects, fixedArrayOfPrimitives, fixedArrayOfPointersToPrimitives); } -HasFixedArrayOfPointers::HasFixedArrayOfPointers() -{ -} - HasFixedArrayOfPointers::~HasFixedArrayOfPointers() { } -SimpleInterface::SimpleInterface() -{ -} - -SimpleInterface::~SimpleInterface() -{ -} - InterfaceTester::InterfaceTester() : interface(0) { } -InterfaceTester::~InterfaceTester() -{ -} - int InterfaceTester::capacity() { return interface->capacity(); @@ -1780,14 +1577,6 @@ void InterfaceTester::setInterface(SimpleInterface* i) interface = i; } -HasFunctionPtrField::HasFunctionPtrField() -{ -} - -HasFunctionPtrField::~HasFunctionPtrField() -{ -} - void va_listFunction(va_list v) { } @@ -1859,7 +1648,6 @@ const char32_t* TestCSharpString32(const char32_t* in, const char32_t** out) return ret.data(); } -ConversionFunctions::ConversionFunctions() = default; ConversionFunctions::operator short* () { return &field; } ConversionFunctions::operator short& () { return field; } ConversionFunctions::operator short() { return field; } diff --git a/tests/CSharp/CSharp.h b/tests/CSharp/CSharp.h index e794cc3b..b3a58321 100644 --- a/tests/CSharp/CSharp.h +++ b/tests/CSharp/CSharp.h @@ -24,7 +24,6 @@ public: Foo(char16_t ch); Foo(wchar_t ch); Foo(const Foo& other); - ~Foo(); int method(); int operator[](int i) const; int operator[](unsigned int i); @@ -111,7 +110,6 @@ public: Bar(); Bar(Qux qux); Bar(Items item); - ~Bar(); int method(); const Foo& operator[](int i) const; Foo& operator[](int i); @@ -143,13 +141,8 @@ private: Foo m_foo; }; -Bar::Bar() : index(0) {} - class DLL_API ForceCreationOfInterface : public Foo, public Bar { -public: - ForceCreationOfInterface(); - ~ForceCreationOfInterface(); }; class DLL_API Baz : public Foo, public Bar @@ -165,7 +158,6 @@ public: Baz(); Baz(Bar::Items item); - ~Baz(); int P; @@ -293,8 +285,6 @@ public: class DLL_API TestRenaming { public: - TestRenaming(); - ~TestRenaming(); void name(); void Name(); int property(); @@ -312,7 +302,6 @@ enum class Flags class DLL_API UsesPointerToEnum { public: - UsesPointerToEnum(); Flags* _flags; void hasPointerToEnumInParam(Flags* flag); }; @@ -364,7 +353,6 @@ namespace Qt class DLL_API QColor { public: - QColor(); QColor(Qt::GlobalColor color); }; @@ -498,7 +486,6 @@ public: class DLL_API HasOverridesWithChangedAccessBase { public: - HasOverridesWithChangedAccessBase(); virtual void privateOverride(int i = 5); protected: virtual void publicOverride(); @@ -549,8 +536,6 @@ class DLL_API IgnoredTypeInheritingNonIgnoredWithNoEmptyCtor : public P class DLL_API HasOverriddenInManaged { public: - HasOverriddenInManaged(); - ~HasOverriddenInManaged(); void setOverriddenInManaged(Baz *value); int callOverriddenInManaged(); private: @@ -700,7 +685,6 @@ private: class DLL_API CallDtorVirtually : public HasVirtualDtor1 { public: - CallDtorVirtually(); ~CallDtorVirtually(); static bool Destroyed; static HasVirtualDtor1* getHasVirtualDtor1(HasVirtualDtor1* returned); @@ -751,23 +735,17 @@ public: class DLL_API HasProtectedVirtual { -public: - HasProtectedVirtual(); protected: virtual void protectedVirtual(); }; class DLL_API InheritanceBuffer : public Foo, public HasProtectedVirtual { -public: - InheritanceBuffer(); - ~InheritanceBuffer(); }; class DLL_API InheritsProtectedVirtualFromSecondaryBase : public InheritanceBuffer { public: - InheritsProtectedVirtualFromSecondaryBase(); ~InheritsProtectedVirtualFromSecondaryBase(); protected: void protectedVirtual(); @@ -787,7 +765,6 @@ class HasOverrideOfHasPropertyWithDerivedType; class DLL_API HasPropertyWithDerivedType { public: - HasPropertyWithDerivedType(); HasOverrideOfHasPropertyWithDerivedType* hasPropertyWithDerivedTypeSubclass; virtual void causeRenamingError(); }; @@ -795,7 +772,6 @@ public: class DLL_API HasOverrideOfHasPropertyWithDerivedType : public HasPropertyWithDerivedType { public: - HasOverrideOfHasPropertyWithDerivedType(); virtual void causeRenamingError(); }; @@ -815,20 +791,16 @@ public: class DLL_API OverrideFromIndirectSecondaryBaseBase { public: - OverrideFromIndirectSecondaryBaseBase(); virtual int property(); }; class DLL_API OverrideFromDirectSecondaryBase : public Foo, public OverrideFromIndirectSecondaryBaseBase { -public: - OverrideFromDirectSecondaryBase(); }; class DLL_API OverrideFromIndirectSecondaryBase : public OverrideFromDirectSecondaryBase { public: - OverrideFromIndirectSecondaryBase(); int property(); }; @@ -861,8 +833,6 @@ TemplateWithDependentField::TemplateWithDependentField() class DLL_API DerivesFromTemplateInstantiation : public TemplateWithDependentField { -public: - DerivesFromTemplateInstantiation(); }; DLL_API int PassConstantArrayRef(int(&arr)[2]); @@ -870,7 +840,6 @@ DLL_API int PassConstantArrayRef(int(&arr)[2]); class DLL_API TestComparison { public: - TestComparison(); int A; float B; bool operator ==(const TestComparison& other) const; @@ -879,7 +848,6 @@ public: class DLL_API OverridePropertyFromIndirectPrimaryBaseBase { public: - OverridePropertyFromIndirectPrimaryBaseBase(); virtual ~OverridePropertyFromIndirectPrimaryBaseBase(); virtual int property() = 0; virtual void setProperty(int value) = 0; @@ -888,21 +856,18 @@ public: class DLL_API OverridePropertyFromDirectPrimaryBase : public OverridePropertyFromIndirectPrimaryBaseBase { public: - OverridePropertyFromDirectPrimaryBase(); void setProperty(int value); }; class DLL_API OverridePropertyFromIndirectPrimaryBase : public OverridePropertyFromDirectPrimaryBase { public: - OverridePropertyFromIndirectPrimaryBase(); int property(); }; class DLL_API AbstractOverrideFromSecondaryBase : public Foo, public OverridePropertyFromIndirectPrimaryBaseBase { public: - AbstractOverrideFromSecondaryBase(); virtual ~AbstractOverrideFromSecondaryBase(); virtual void setProperty(int value) = 0; }; @@ -910,7 +875,6 @@ public: class DLL_API QObject { public: - QObject(); virtual ~QObject(); virtual void event(); }; @@ -919,7 +883,6 @@ class DLL_API QPaintDevice { public: QPaintDevice(); - ~QPaintDevice(); int test; virtual void changeVTableLayout(); }; @@ -928,7 +891,6 @@ class DLL_API QWidget : public QObject, QPaintDevice { public: QWidget(); - ~QWidget(); virtual void event(); private: QObject child; @@ -938,7 +900,6 @@ class DLL_API QPainter { public: QPainter(QPaintDevice& paintDevice); - ~QPainter(); }; class DLL_API QApplication : public QObject @@ -956,10 +917,9 @@ public: char* property(); }; -class InheritsFromHasSamePropertyInDerivedAbstractType : public HasSamePropertyInDerivedAbstractType +class DLL_API InheritsFromHasSamePropertyInDerivedAbstractType : public HasSamePropertyInDerivedAbstractType { public: - InheritsFromHasSamePropertyInDerivedAbstractType(); virtual ~InheritsFromHasSamePropertyInDerivedAbstractType(); virtual int property() = 0; }; @@ -989,7 +949,6 @@ public: class DLL_API VirtualDtorAddedInDerived : public Foo { public: - VirtualDtorAddedInDerived(); virtual ~VirtualDtorAddedInDerived(); static bool dtorCalled; }; @@ -1141,7 +1100,6 @@ class DLL_API TestString { public: TestString(); - ~TestString(); const wchar_t* unicodeConst; wchar_t* unicode; }; @@ -1154,7 +1112,6 @@ DLL_API void usesDecltypeFunctionPointer(funcPtr func); class DLL_API PrimaryBaseWithAbstractWithDefaultArg { public: - PrimaryBaseWithAbstractWithDefaultArg(); ~PrimaryBaseWithAbstractWithDefaultArg(); virtual void abstractWithNoDefaultArg(const Foo& foo) = 0; }; @@ -1162,7 +1119,6 @@ public: class DLL_API SecondaryBaseWithAbstractWithDefaultArg { public: - SecondaryBaseWithAbstractWithDefaultArg(); ~SecondaryBaseWithAbstractWithDefaultArg(); virtual void abstract(const Foo& foo = Foo()) = 0; }; @@ -1170,7 +1126,6 @@ public: class DLL_API HasSecondaryBaseWithAbstractWithDefaultArg : public PrimaryBaseWithAbstractWithDefaultArg, public SecondaryBaseWithAbstractWithDefaultArg { public: - HasSecondaryBaseWithAbstractWithDefaultArg(); ~HasSecondaryBaseWithAbstractWithDefaultArg(); virtual void abstract(const Foo& foo = Foo()); virtual void abstractWithNoDefaultArg(const Foo& foo = Foo()); @@ -1179,21 +1134,18 @@ public: class DLL_API MissingObjectOnVirtualCallSecondaryBase { public: - MissingObjectOnVirtualCallSecondaryBase(); virtual int f(); }; class DLL_API MissingObjectOnVirtualCall : public HasVirtualDtor1, public MissingObjectOnVirtualCallSecondaryBase { public: - MissingObjectOnVirtualCall(); int f(); }; class DLL_API HasMissingObjectOnVirtualCall { public: - HasMissingObjectOnVirtualCall(); int makeMissingObjectOnVirtualCall(); void setMissingObjectOnVirtualCall(MissingObjectOnVirtualCall* value); private: @@ -1232,16 +1184,12 @@ private: class DLL_API HasBaseSetter { public: - HasBaseSetter(); - ~HasBaseSetter(); virtual void setBaseSetter(int value); }; class DLL_API HasGetterAndOverriddenSetter : public HasBaseSetter { public: - HasGetterAndOverriddenSetter(); - ~HasGetterAndOverriddenSetter(); void setBaseSetter(int value); int baseSetter(); protected: @@ -1300,7 +1248,6 @@ struct DLL_API ComplexArrayElement struct DLL_API HasComplexArray { - HasComplexArray(); ComplexArrayElement complexArray[ARRAY_LENGTH_MACRO]; }; @@ -1335,8 +1282,6 @@ inline namespace InlineNamespace class DLL_API TestArrays { public: - TestArrays(); - ~TestArrays(); int takeArrays(Foo* arrayOfPointersToObjects[], int arrayOfPrimitives[], Foo arrayOfObjects[]) const; int takeArrays(Foo* fixedArrayOfPointersToObjects[3], int fixedArrayOfPrimitives[4], int* fixedArrayOfPointersToPrimitives[5]) const; @@ -1355,7 +1300,6 @@ class TestForwardedClassInAnotherUnit class DLL_API HasFixedArrayOfPointers { public: - HasFixedArrayOfPointers(); ~HasFixedArrayOfPointers(); Foo* fixedArrayOfPointers[3]; }; @@ -1371,8 +1315,6 @@ static int FOOBAR_CONSTANT = 42; class DLL_API SimpleInterface { public: - SimpleInterface(); - ~SimpleInterface(); virtual int size() const = 0; virtual int capacity() const = 0; virtual void* get(int n) = 0; @@ -1383,7 +1325,6 @@ class DLL_API InterfaceTester { public: InterfaceTester(); - ~InterfaceTester(); int capacity(); int size(); void* get(int n); @@ -1395,8 +1336,6 @@ private: class DLL_API HasFunctionPtrField { public: - HasFunctionPtrField(); - ~HasFunctionPtrField(); int (*functionPtrField)(const char*); int (*functionPtrTakeFunctionPtrField)(int(*TakenInFuncPtrField)()); }; @@ -1456,7 +1395,6 @@ struct TestVariableWithoutType struct DLL_API ConversionFunctions { - ConversionFunctions(); operator short* (); operator short& (); operator short(); diff --git a/tests/CSharp/CSharpTemplates.h b/tests/CSharp/CSharpTemplates.h index 9bdce147..0da27274 100644 --- a/tests/CSharp/CSharpTemplates.h +++ b/tests/CSharp/CSharpTemplates.h @@ -6,6 +6,12 @@ #include #include +class DeriveProtectedDtor +{ +protected: + ~DeriveProtectedDtor() {} +}; + class DLL_API QString { }; @@ -451,6 +457,7 @@ class TemplateWithIndexer { public: TemplateWithIndexer(); + ~TemplateWithIndexer(); T& operator[](int i); T& operator[](const T& key); T& operator[](const char* string); @@ -466,6 +473,11 @@ TemplateWithIndexer::TemplateWithIndexer() { } +template +TemplateWithIndexer::~TemplateWithIndexer() +{ +} + template T& TemplateWithIndexer::operator[](int i) { @@ -784,36 +796,6 @@ template<> inline void* qbswap<1>(const void *source, size_t count, void *dest) return 0; } -// force the symbols for the template instantiations because we do not have the auto-compilation for the generated C++ source -template class DLL_API IndependentFields; -template class DLL_API IndependentFields; -template class DLL_API IndependentFields; -template class DLL_API IndependentFields; -template class DLL_API IndependentFields; -template class DLL_API Base; -template class DLL_API DependentValueFields; -template class DLL_API DependentValueFields; -template class DLL_API DependentValueFields; -template class DLL_API DependentPointerFields; -template class DLL_API VirtualTemplate; -template class DLL_API VirtualTemplate; -template class DLL_API HasDefaultTemplateArgument; -template class DLL_API DerivedChangesTypeName; -template class DLL_API TemplateWithIndexer; -template class DLL_API TemplateWithIndexer; -template class DLL_API TemplateWithIndexer; -template class DLL_API TemplateWithIndexer; -template class DLL_API TemplateWithIndexer; -template class DLL_API TemplateWithIndexer; -template class DLL_API TemplateWithIndexer; -template class DLL_API TemplateDerivedFromRegularDynamic; -template class DLL_API HasCtorWithMappedToEnum; -template class DLL_API TwoTemplateArgs; -template class DLL_API TwoTemplateArgs; -template class DLL_API TwoTemplateArgs; -template class DLL_API TwoTemplateArgs; -template class DLL_API TwoTemplateArgs; - class TestForwardedClassInAnotherUnit; // Forward declaration of class as friend diff --git a/tests/Common/Common.cpp b/tests/Common/Common.cpp index 85b86a2d..80c23c7b 100644 --- a/tests/Common/Common.cpp +++ b/tests/Common/Common.cpp @@ -1,42 +1,6 @@ #include "Common.h" #include -TestPacking::TestPacking() -{ -} - -TestPacking1::TestPacking1() -{ -} - -TestPacking1::~TestPacking1() -{ -} - -TestPacking2::TestPacking2() -{ -} - -TestPacking2::~TestPacking2() -{ -} - -TestPacking4::TestPacking4() -{ -} - -TestPacking4::~TestPacking4() -{ -} - -TestPacking8::TestPacking8() -{ -} - -TestPacking8::~TestPacking8() -{ -} - Foo::NestedAbstract::~NestedAbstract() { } @@ -155,10 +119,6 @@ bool operator ==(Bar::Item item, const Bar& bar) return item == bar.RetItem1(); } -Bar2::Nested::Nested() -{ -} - Bar2::Nested::operator int() const { return 300; @@ -483,14 +443,6 @@ void va_listFunction(va_list v) { } -TestNestedTypes::TestNestedTypes() -{ -} - -TestNestedTypes::~TestNestedTypes() -{ -} - void TestDelegates::MarshalUnattributedDelegate(DelegateInGlobalNamespace del) { } @@ -584,14 +536,6 @@ void DelegateNamespace::f2(void (*)()) { } -HasStdString::HasStdString() -{ -} - -HasStdString::~HasStdString() -{ -} - std::string HasStdString::testStdString(const std::string& s) { return s + "_test"; @@ -810,11 +754,6 @@ int TestProperties::GetArchiveName() const { return 20; } - -HasOverridenSetter::HasOverridenSetter() -{ -} - void HasOverridenSetter::setVirtual(bool value) { } @@ -873,23 +812,13 @@ Bar& TestIndexedProperties::operator[](const Foo& key) return bar; } -TestVariables::TestVariables() -{ -} - int TestVariables::VALUE; void TestVariables::SetValue(int value) { VALUE = value; } -TestWideStrings::TestWideStrings() -{ -} - LPCWSTR TestWideStrings::GetWidePointer() { return L"Hello"; } LPCWSTR TestWideStrings::GetWideNullPointer() { return 0; } -TestFixedArrays::TestFixedArrays() {} - InternalCtorAmbiguity::InternalCtorAmbiguity(void* param) { // cause a crash to indicate this is the incorrect ctor to invoke @@ -977,10 +906,6 @@ void HasVirtualProperty::setProtectedProperty(int value) { } -ChangedAccessOfInheritedProperty::ChangedAccessOfInheritedProperty() -{ -} - int ChangedAccessOfInheritedProperty::getProperty() { return 2; @@ -999,10 +924,6 @@ void ChangedAccessOfInheritedProperty::setProtectedProperty(int value) { } -ReturnsEmpty::ReturnsEmpty() -{ -} - Empty ReturnsEmpty::getEmpty() { return Empty(); @@ -1032,10 +953,6 @@ HasProblematicFields::HasProblematicFields() : b(false), c(0) { } -HasVirtualReturningHasProblematicFields::HasVirtualReturningHasProblematicFields() -{ -} - HasProblematicFields HasVirtualReturningHasProblematicFields::returnsProblematicFields() { return HasProblematicFields(); @@ -1055,45 +972,20 @@ int DerivedClassVirtual::retInt(const Foo2& foo) { return 2; } - -DerivedClassAbstractVirtual::~DerivedClassAbstractVirtual() -{ -} - -DerivedClassOverrideAbstractVirtual::DerivedClassOverrideAbstractVirtual() -{ -} - int DerivedClassOverrideAbstractVirtual::retInt(const Foo& foo) { return 1; } -BufferForVirtualFunction::BufferForVirtualFunction() -{ -} - -OverridesNonDirectVirtual::OverridesNonDirectVirtual() -{ -} - int OverridesNonDirectVirtual::retInt(const Foo& foo) { return 3; } -AbstractWithVirtualDtor::AbstractWithVirtualDtor() -{ -} - AbstractWithVirtualDtor::~AbstractWithVirtualDtor() { } -NonTrivialDtorBase::NonTrivialDtorBase() -{ -} - NonTrivialDtorBase::~NonTrivialDtorBase() { } @@ -1120,19 +1012,11 @@ void NonTrivialDtor::setDtorCalled(bool value) bool NonTrivialDtor::dtorCalled = false; -DerivedFromTemplateInstantiationWithVirtual::DerivedFromTemplateInstantiationWithVirtual() -{ -} - int func_union(union_t u) { return u.c; } -HasProtectedEnum::HasProtectedEnum() -{ -} - void HasProtectedEnum::function(ProtectedEnum param) { } @@ -1145,18 +1029,6 @@ void FuncWithTemplateTypeAlias(TypeAliasTemplate i) { } -HasAbstractOperator::~HasAbstractOperator() -{ -} - -HasOverloadsWithDifferentPointerKindsToSameType::HasOverloadsWithDifferentPointerKindsToSameType() -{ -} - -HasOverloadsWithDifferentPointerKindsToSameType::~HasOverloadsWithDifferentPointerKindsToSameType() -{ -} - void HasOverloadsWithDifferentPointerKindsToSameType::overload(int& i) { } @@ -1237,31 +1109,11 @@ HasCopyAndMoveConstructor::HasCopyAndMoveConstructor(HasCopyAndMoveConstructor&& field = other.field; } -HasCopyAndMoveConstructor::~HasCopyAndMoveConstructor() -{ -} - int HasCopyAndMoveConstructor::getField() { return field; } -HasVirtualFunctionsWithStringParams::HasVirtualFunctionsWithStringParams() -{ -} - -HasVirtualFunctionsWithStringParams::~HasVirtualFunctionsWithStringParams() -{ -} - -ImplementsVirtualFunctionsWithStringParams::ImplementsVirtualFunctionsWithStringParams() -{ -} - -ImplementsVirtualFunctionsWithStringParams::~ImplementsVirtualFunctionsWithStringParams() -{ -} - void ImplementsVirtualFunctionsWithStringParams::PureVirtualFunctionWithStringParams(std::string testString1, std::string testString2) { } @@ -1271,14 +1123,6 @@ int HasVirtualFunctionsWithStringParams::VirtualFunctionWithStringParam(std::str return 5; } -HasVirtualFunctionWithBoolParams::HasVirtualFunctionWithBoolParams() -{ -} - -HasVirtualFunctionWithBoolParams::~HasVirtualFunctionWithBoolParams() -{ -} - bool HasVirtualFunctionWithBoolParams::virtualFunctionWithBoolParamAndReturnsBool(bool testBool) { return testBool; @@ -1288,10 +1132,6 @@ HasProtectedCtorWithProtectedParam::HasProtectedCtorWithProtectedParam(Protected { } -SecondaryBaseWithIgnoredVirtualMethod::SecondaryBaseWithIgnoredVirtualMethod() -{ -} - SecondaryBaseWithIgnoredVirtualMethod::~SecondaryBaseWithIgnoredVirtualMethod() { } @@ -1304,10 +1144,6 @@ void SecondaryBaseWithIgnoredVirtualMethod::ignored(const IgnoredType& ignoredPa { } -DerivedFromSecondaryBaseWithIgnoredVirtualMethod::DerivedFromSecondaryBaseWithIgnoredVirtualMethod() -{ -} - DerivedFromSecondaryBaseWithIgnoredVirtualMethod::~DerivedFromSecondaryBaseWithIgnoredVirtualMethod() { } @@ -1328,14 +1164,6 @@ AmbiguousParamNames::~AmbiguousParamNames() { } -HasPropertyNamedAsParent::HasPropertyNamedAsParent() -{ -} - -HasPropertyNamedAsParent::~HasPropertyNamedAsParent() -{ -} - void integerOverload(int i) { } @@ -1380,7 +1208,7 @@ LPCSTR TakeTypedefedMappedType(LPCSTR string) return UTF8.data(); } -StructWithCopyCtor::StructWithCopyCtor() {} +StructWithCopyCtor::StructWithCopyCtor() : mBits(0) {} StructWithCopyCtor::StructWithCopyCtor(const StructWithCopyCtor& other) : mBits(other.mBits) {} uint16_t TestStructWithCopyCtorByValue(StructWithCopyCtor s) @@ -1396,30 +1224,14 @@ DerivedCovariant::~DerivedCovariant() { } -NonPrimitiveType::NonPrimitiveType() -{ -} - int NonPrimitiveType::GetFoo() { return foo; } -TestFixedNonPrimitiveArrays::TestFixedNonPrimitiveArrays() -{ -} - -TestGetterSetterToProperties::TestGetterSetterToProperties() -{ -} - int TestGetterSetterToProperties::getWidth() { return 640; } int TestGetterSetterToProperties::getHeight() { return 480; } -PointerToTypedefPointerTest::PointerToTypedefPointerTest() -{ -} - void DLL_API PointerToTypedefPointerTestMethod(LPPointerToTypedefPointerTest* lp, int valToSet) { (*(*lp)).val = valToSet; @@ -1435,7 +1247,7 @@ TestArraysPointers::TestArraysPointers(MyEnum* values, int count) if (values && count) Value = values[0]; } -TestCopyConstructorRef::TestCopyConstructorRef() +TestCopyConstructorRef::TestCopyConstructorRef() : A(0), B(0) { } diff --git a/tests/Common/Common.h b/tests/Common/Common.h index ab105bcb..542788d7 100644 --- a/tests/Common/Common.h +++ b/tests/Common/Common.h @@ -14,39 +14,26 @@ public: int i1; int i2; bool b; - TestPacking(); }; #pragma pack(1) class DLL_API TestPacking1: public TestPacking { -public: - TestPacking1(); - ~TestPacking1(); }; #pragma pack(2) class DLL_API TestPacking2: public TestPacking { -public: - TestPacking2(); - ~TestPacking2(); }; #pragma pack(4) class DLL_API TestPacking4: public TestPacking { -public: - TestPacking4(); - ~TestPacking4(); }; #pragma pack(8) class DLL_API TestPacking8: public TestPacking { -public: - TestPacking8(); - ~TestPacking8(); }; #pragma pack() @@ -76,7 +63,7 @@ public: EmptyEnum2 }; - class NestedAbstract + class DLL_API NestedAbstract { public: virtual ~NestedAbstract(); @@ -168,7 +155,6 @@ struct DLL_API Bar2 : public Bar struct DLL_API Nested { - Nested(); operator int() const; }; @@ -605,7 +591,6 @@ private: class DLL_API HasOverridenSetter : public TestProperties { public: - HasOverridenSetter(); void setVirtual(bool value) override; int virtualSetterReturnsBoolean() override; @@ -660,7 +645,6 @@ public: // Tests variables struct DLL_API TestVariables { - TestVariables(); static int VALUE; void SetValue(int value = VALUE); }; @@ -668,7 +652,6 @@ struct DLL_API TestVariables typedef const wchar_t * LPCWSTR; struct DLL_API TestWideStrings { - TestWideStrings(); LPCWSTR GetWidePointer(); LPCWSTR GetWideNullPointer(); }; @@ -680,7 +663,6 @@ typedef void (*VoidPtrRetFunctionTypedef) (); class DLL_API TestFixedArrays { public: - TestFixedArrays(); VoidPtrRetFunctionTypedef Array[10]; #ifndef _MSC_VER TestWideStrings ZeroSizedClassArray[0]; @@ -700,7 +682,6 @@ public: class DLL_API NonPrimitiveType { public: - NonPrimitiveType(); int GetFoo(); int foo; @@ -709,13 +690,11 @@ public: class DLL_API TestFixedNonPrimitiveArrays { public: - TestFixedNonPrimitiveArrays(); NonPrimitiveType NonPrimitiveTypeArray[3]; }; struct DLL_API TestGetterSetterToProperties { - TestGetterSetterToProperties(); int getWidth(); int getHeight(); }; @@ -784,8 +763,6 @@ DLL_API void va_listFunction(va_list v); struct DLL_API TestNestedTypes { public: - TestNestedTypes(); - ~TestNestedTypes(); union as_types { int as_int; @@ -806,8 +783,6 @@ public: class DLL_API HasStdString { public: - HasStdString(); - ~HasStdString(); std::string testStdString(const std::string& s); std::string testStdStringPassedByValue(std::string s); std::string s; @@ -909,7 +884,6 @@ protected: class DLL_API ChangedAccessOfInheritedProperty : public HasVirtualProperty { public: - ChangedAccessOfInheritedProperty(); int getProtectedProperty(); void setProtectedProperty(int value); protected: @@ -924,7 +898,6 @@ class DLL_API Empty class DLL_API ReturnsEmpty { public: - ReturnsEmpty(); Empty getEmpty(); }; @@ -944,7 +917,6 @@ public: class DLL_API HasVirtualReturningHasProblematicFields { public: - HasVirtualReturningHasProblematicFields(); virtual HasProblematicFields returnsProblematicFields(); }; @@ -966,27 +938,22 @@ public: class DLL_API DerivedClassAbstractVirtual : public DerivedClassVirtual { public: - ~DerivedClassAbstractVirtual(); virtual int retInt(const Foo& foo) = 0; }; class DLL_API DerivedClassOverrideAbstractVirtual : public DerivedClassAbstractVirtual { public: - DerivedClassOverrideAbstractVirtual(); virtual int retInt(const Foo& foo); }; class DLL_API BufferForVirtualFunction : public BaseClassVirtual { -public: - BufferForVirtualFunction(); }; class DLL_API OverridesNonDirectVirtual : public BufferForVirtualFunction { public: - OverridesNonDirectVirtual(); virtual int retInt(const Foo& foo); }; @@ -1064,7 +1031,6 @@ AbstractTemplate::AbstractTemplate() class DLL_API AbstractWithVirtualDtor { public: - AbstractWithVirtualDtor(); virtual ~AbstractWithVirtualDtor(); virtual void abstract() = 0; }; @@ -1072,7 +1038,6 @@ public: class DLL_API NonTrivialDtorBase { public: - NonTrivialDtorBase(); ~NonTrivialDtorBase(); }; @@ -1127,8 +1092,6 @@ int FunctionTemplateWithDependentTypeDefaultExpr(size_t size = sizeof(T)) { class DLL_API DerivedFromTemplateInstantiationWithVirtual : public TemplateWithVirtual { -public: - DerivedFromTemplateInstantiationWithVirtual(); }; typedef union @@ -1140,8 +1103,6 @@ int DLL_API func_union(union_t u); class DLL_API HasProtectedEnum { -public: - HasProtectedEnum(); protected: enum class ProtectedEnum { @@ -1191,7 +1152,6 @@ private: class DLL_API HasAbstractOperator { public: - ~HasAbstractOperator(); virtual bool operator==(const HasAbstractOperator& other) = 0; }; @@ -1251,8 +1211,6 @@ enum class DLL_API HasOverloadsWithDifferentPointerKindsToSameType { public: - HasOverloadsWithDifferentPointerKindsToSameType(); - ~HasOverloadsWithDifferentPointerKindsToSameType(); void overload(int& i); void overload(int&& i); void overload(const int& i); @@ -1278,7 +1236,6 @@ public: HasCopyAndMoveConstructor(int value); HasCopyAndMoveConstructor(const HasCopyAndMoveConstructor& other); HasCopyAndMoveConstructor(HasCopyAndMoveConstructor&& other); - ~HasCopyAndMoveConstructor(); int getField(); private: int field; @@ -1287,8 +1244,6 @@ private: class DLL_API HasVirtualFunctionsWithStringParams { public: - HasVirtualFunctionsWithStringParams(); - ~HasVirtualFunctionsWithStringParams(); virtual void PureVirtualFunctionWithStringParams(std::string testString1, std::string testString2) = 0; virtual int VirtualFunctionWithStringParam(std::string testString); }; @@ -1296,16 +1251,12 @@ public: class DLL_API ImplementsVirtualFunctionsWithStringParams : public HasVirtualFunctionsWithStringParams { public: - ImplementsVirtualFunctionsWithStringParams(); - ~ImplementsVirtualFunctionsWithStringParams(); virtual void PureVirtualFunctionWithStringParams(std::string testString1, std::string testString2); }; class DLL_API HasVirtualFunctionWithBoolParams { public: - HasVirtualFunctionWithBoolParams(); - ~HasVirtualFunctionWithBoolParams(); virtual bool virtualFunctionWithBoolParamAndReturnsBool(bool testBool); }; @@ -1322,7 +1273,7 @@ protected: class DLL_API SecondaryBaseWithIgnoredVirtualMethod { public: - SecondaryBaseWithIgnoredVirtualMethod(); + // HACK: do not delete: work around https://github.com/mono/CppSharp/issues/1534 ~SecondaryBaseWithIgnoredVirtualMethod(); virtual void generated(); virtual void ignored(const IgnoredType& ignoredParam); @@ -1331,7 +1282,7 @@ public: class DLL_API DerivedFromSecondaryBaseWithIgnoredVirtualMethod : public Foo, public SecondaryBaseWithIgnoredVirtualMethod { public: - DerivedFromSecondaryBaseWithIgnoredVirtualMethod(); + // HACK: do not delete: work around https://github.com/mono/CppSharp/issues/1534 ~DerivedFromSecondaryBaseWithIgnoredVirtualMethod(); void generated(); void ignored(const IgnoredType& ignoredParam); @@ -1347,8 +1298,6 @@ public: class DLL_API HasPropertyNamedAsParent { public: - HasPropertyNamedAsParent(); - ~HasPropertyNamedAsParent(); int hasPropertyNamedAsParent; }; @@ -1539,7 +1488,6 @@ QScopedPointer d_ptr; struct DLL_API PointerToTypedefPointerTest { - PointerToTypedefPointerTest(); int val; }; typedef PointerToTypedefPointerTest *LPPointerToTypedefPointerTest; diff --git a/tests/Encodings/Encodings.cpp b/tests/Encodings/Encodings.cpp index 7c4289e8..3e8ace21 100644 --- a/tests/Encodings/Encodings.cpp +++ b/tests/Encodings/Encodings.cpp @@ -2,14 +2,6 @@ std::string Foo::StringVariable = ""; -Foo::Foo() -{ -} - -Foo::~Foo() -{ -} - // TODO: move this, it has nothing to do with Unicode, it's here only not to break the CLI branch int Foo::operator[](int i) const { diff --git a/tests/Encodings/Encodings.h b/tests/Encodings/Encodings.h index 9ab7efd4..3fe2203d 100644 --- a/tests/Encodings/Encodings.h +++ b/tests/Encodings/Encodings.h @@ -4,9 +4,6 @@ class DLL_API Foo { public: - Foo(); - ~Foo(); - const char* Unicode; static std::string StringVariable; diff --git a/tests/NamespacesBase/NamespacesBase.cpp b/tests/NamespacesBase/NamespacesBase.cpp index 51757f77..c6365348 100644 --- a/tests/NamespacesBase/NamespacesBase.cpp +++ b/tests/NamespacesBase/NamespacesBase.cpp @@ -41,14 +41,6 @@ int HasVirtualInCore::virtualInCore(int parameter) return 1; } -SecondaryBase::SecondaryBase() -{ -} - -SecondaryBase::~SecondaryBase() -{ -} - void SecondaryBase::function() { } diff --git a/tests/NamespacesBase/NamespacesBase.h b/tests/NamespacesBase/NamespacesBase.h index d6e0544b..d00d275d 100644 --- a/tests/NamespacesBase/NamespacesBase.h +++ b/tests/NamespacesBase/NamespacesBase.h @@ -13,11 +13,6 @@ namespace OverlappingNamespace class DLL_API InBaseLib { - public: - InBaseLib() - { - - }; }; } @@ -96,10 +91,5 @@ typedef DerivedFromSecondaryBaseInDependency RenameDerivedBeforeBase; class DLL_API SecondaryBase { public: - SecondaryBase(); - ~SecondaryBase(); void function(); }; - -// force the symbols for the template instantiations because we do not have the auto-compilation for the generated C++ source -template class DLL_API TemplateClass; diff --git a/tests/NamespacesDerived/NamespacesDerived.Gen.cs b/tests/NamespacesDerived/NamespacesDerived.Gen.cs index 3cf6eaaa..27adc4a4 100644 --- a/tests/NamespacesDerived/NamespacesDerived.Gen.cs +++ b/tests/NamespacesDerived/NamespacesDerived.Gen.cs @@ -23,7 +23,7 @@ namespace CppSharp.Tests module.IncludeDirs.Add(Path.GetFullPath(GetTestsDirectory(@base))); module.Headers.Add($"{@base}.h"); module.OutputNamespace = @base; - module.LibraryDirs.Add(driver.Options.OutputDir); + module.LibraryDirs.AddRange(driver.Options.Modules[1].LibraryDirs); module.Libraries.Add($"{@base}.Native"); driver.Options.Modules[1].Dependencies.Add(module); } diff --git a/tests/NamespacesDerived/NamespacesDerived.cpp b/tests/NamespacesDerived/NamespacesDerived.cpp index e463a7c3..e09bc1c3 100644 --- a/tests/NamespacesDerived/NamespacesDerived.cpp +++ b/tests/NamespacesDerived/NamespacesDerived.cpp @@ -33,14 +33,6 @@ void Derived::setNestedNSComponent(OverlappingNamespace::InBaseLib c) nestedNSComponent = c; } -Derived2::Derived2() -{ -} - -Derived2::~Derived2() -{ -} - Base3 Derived2::getBase() { return baseComponent; @@ -89,24 +81,26 @@ TemplateWithIndependentFields DerivedFromExternalSpecialization::returnEx return TemplateWithIndependentFields(); } -HasVirtualInDependency::HasVirtualInDependency() +int HasVirtualInDependency::callManagedOverride() { + return managedObject->virtualInCore(0); } -int HasVirtualInDependency::callManagedOverride() +bool operator<<(const Base& b, const char* str) { - return managedObject->virtualInCore(0); + return false; } -DerivedFromSecondaryBaseInDependency::DerivedFromSecondaryBaseInDependency() +const char* TestComments::GetIOHandlerControlSequence(char ch) { + return 0; } -DerivedFromSecondaryBaseInDependency::~DerivedFromSecondaryBaseInDependency() +int TestComments::SBAttachInfo(const char* path, bool wait_for) { + return 0; } -bool operator<<(const Base& b, const char* str) +void TestComments::glfwDestroyWindow(int *window) { - return false; } diff --git a/tests/NamespacesDerived/NamespacesDerived.h b/tests/NamespacesDerived/NamespacesDerived.h index 0ddf676a..c8a3ef08 100644 --- a/tests/NamespacesDerived/NamespacesDerived.h +++ b/tests/NamespacesDerived/NamespacesDerived.h @@ -47,8 +47,6 @@ template class TemplateClass; class DLL_API Derived2 : public Base3 { public: - Derived2(); - ~Derived2(); Base3 baseComponent; Base3 getBase(); void setBase(Base3); @@ -68,7 +66,6 @@ private: class DLL_API HasVirtualInDependency : public HasVirtualInCore { public: - HasVirtualInDependency(); HasVirtualInDependency* managedObject; int callManagedOverride(); }; @@ -85,9 +82,6 @@ public: class DLL_API DerivedFromSecondaryBaseInDependency : public Derived, public SecondaryBase { -public: - DerivedFromSecondaryBaseInDependency(); - ~DerivedFromSecondaryBaseInDependency(); }; DLL_API bool operator<<(const Base& b, const char* str); @@ -105,7 +99,7 @@ namespace NamespacesBase /** Note that to prevent extra memory use due to vtable pointer, %HashBase intentionally does not declare a virtual destructor and therefore %HashBase pointers should never be used. */ -class TestComments +class DLL_API TestComments { public: //---------------------------------------------------------------------- diff --git a/tests/Test.Generator.props b/tests/Test.Generator.props index 7d808a08..8ea3c57d 100644 --- a/tests/Test.Generator.props +++ b/tests/Test.Generator.props @@ -18,11 +18,5 @@ - - - - - \ No newline at end of file diff --git a/tests/VTables/VTables.cpp b/tests/VTables/VTables.cpp index 73f5b6e9..d5ce0b13 100644 --- a/tests/VTables/VTables.cpp +++ b/tests/VTables/VTables.cpp @@ -1,14 +1,6 @@ #include "VTables.h" #include -Foo::Foo() -{ -} - -Foo::~Foo() -{ -} - int Foo::vfoo() { return 5; @@ -72,10 +64,6 @@ const char* BaseClassVirtual::getTypeName() return typeid(BaseClassVirtual).name(); } -DerivedClassVirtual::DerivedClassVirtual() -{ -} - int DerivedClassVirtual::retInt() { return 10; diff --git a/tests/VTables/VTables.h b/tests/VTables/VTables.h index 40fa8880..e832fe82 100644 --- a/tests/VTables/VTables.h +++ b/tests/VTables/VTables.h @@ -9,8 +9,6 @@ public: }; - Foo(); - ~Foo(); virtual int vfoo(); virtual int vbar(); @@ -37,6 +35,5 @@ public: class DLL_API DerivedClassVirtual : public BaseClassVirtual { public: - DerivedClassVirtual(); virtual int retInt() override; };