From 1400361711567fd9ef2a98b38986d4c80c2fefe1 Mon Sep 17 00:00:00 2001 From: Tomi Valkeinen Date: Sun, 4 May 2014 11:37:24 +0300 Subject: [PATCH 01/11] build: fix nunit dll filename Linux is case-sensitive with filenames, and as the NUnit library files are lowercase, we need to use lowercase in the build files also. Signed-off-by: Tomi Valkeinen --- build/Tests.lua | 4 ++-- src/Generator.Tests/Generator.Tests.lua | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build/Tests.lua b/build/Tests.lua index e2620543..dd1e908c 100644 --- a/build/Tests.lua +++ b/build/Tests.lua @@ -92,7 +92,7 @@ function LinkNUnit() links { - "NUnit.Framework", + "nunit.framework", "NSubstitute" } end @@ -164,4 +164,4 @@ end function IncludeTests() print("Searching for tests...") IncludeDir(testsdir) -end \ No newline at end of file +end diff --git a/src/Generator.Tests/Generator.Tests.lua b/src/Generator.Tests/Generator.Tests.lua index 78567c87..f8660fc6 100644 --- a/src/Generator.Tests/Generator.Tests.lua +++ b/src/Generator.Tests/Generator.Tests.lua @@ -20,6 +20,6 @@ project "CppSharp.Generator.Tests" "CppSharp", "CppSharp.AST", "CppSharp.Generator", - "NUnit.Framework", + "nunit.framework", "NSubstitute" } From fc7c84b65ab11fea52e29383d7c1471068aa2de2 Mon Sep 17 00:00:00 2001 From: Tomi Valkeinen Date: Wed, 7 May 2014 09:30:10 +0300 Subject: [PATCH 02/11] build: rename osx premake binary Rename osx premake binary to premake5-osx, so that we can add premake5-linux. Signed-off-by: Tomi Valkeinen --- build/{premake5 => premake5-osx} | Bin 1 file changed, 0 insertions(+), 0 deletions(-) rename build/{premake5 => premake5-osx} (100%) diff --git a/build/premake5 b/build/premake5-osx similarity index 100% rename from build/premake5 rename to build/premake5-osx From b8128733784433055ceb6066ed8232d412854324 Mon Sep 17 00:00:00 2001 From: Tomi Valkeinen Date: Wed, 7 May 2014 09:12:10 +0300 Subject: [PATCH 03/11] build: move windows bindings to i686-pc-win32 directory Move windows bindings to i686-pc-win32, the same way as osx bindings are (and linux bindings will be). Signed-off-by: Tomi Valkeinen --- src/CppParser/Bindings/CSharp/{ => i686-pc-win32}/AST.cs | 0 .../Bindings/CSharp/{ => i686-pc-win32}/CppParser.cs | 0 .../Bindings/CSharp/{ => i686-pc-win32}/Target.cs | 0 src/CppParser/Bindings/premake4.lua | 8 +++++--- 4 files changed, 5 insertions(+), 3 deletions(-) rename src/CppParser/Bindings/CSharp/{ => i686-pc-win32}/AST.cs (100%) rename src/CppParser/Bindings/CSharp/{ => i686-pc-win32}/CppParser.cs (100%) rename src/CppParser/Bindings/CSharp/{ => i686-pc-win32}/Target.cs (100%) diff --git a/src/CppParser/Bindings/CSharp/AST.cs b/src/CppParser/Bindings/CSharp/i686-pc-win32/AST.cs similarity index 100% rename from src/CppParser/Bindings/CSharp/AST.cs rename to src/CppParser/Bindings/CSharp/i686-pc-win32/AST.cs diff --git a/src/CppParser/Bindings/CSharp/CppParser.cs b/src/CppParser/Bindings/CSharp/i686-pc-win32/CppParser.cs similarity index 100% rename from src/CppParser/Bindings/CSharp/CppParser.cs rename to src/CppParser/Bindings/CSharp/i686-pc-win32/CppParser.cs diff --git a/src/CppParser/Bindings/CSharp/Target.cs b/src/CppParser/Bindings/CSharp/i686-pc-win32/Target.cs similarity index 100% rename from src/CppParser/Bindings/CSharp/Target.cs rename to src/CppParser/Bindings/CSharp/i686-pc-win32/Target.cs diff --git a/src/CppParser/Bindings/premake4.lua b/src/CppParser/Bindings/premake4.lua index 711660df..4ece2bfb 100644 --- a/src/CppParser/Bindings/premake4.lua +++ b/src/CppParser/Bindings/premake4.lua @@ -26,10 +26,12 @@ project "CppSharp.Parser.CSharp" links { "CppSharp.Runtime" } - if os.is_osx() then + if os.is_windows() then + files { "CSharp/i686-pc-win32/**.cs" } + elseif os.is_osx() then files { "CSharp/i686-apple-darwin12.4.0/**.cs" } else - files { "CSharp/*.cs" } + print "Unknown architecture" end configuration "" @@ -65,4 +67,4 @@ if string.starts(action, "vs") and os.is_windows() then configuration "*" links { "CppSharp.CppParser" } -end \ No newline at end of file +end From 7f612e22e573bc4979ff96e2715207ae115217b4 Mon Sep 17 00:00:00 2001 From: Tomi Valkeinen Date: Mon, 5 May 2014 14:16:08 +0300 Subject: [PATCH 04/11] build: remove setting libdirs in premake4.lua "libdirs { libdir }" in the main premake4.lua file causes Debug_x32 directory to be added for the libdirs for all builds. I think that's a bug in premake, as at the same place setting, say, "targetdir" works fine. However, setting "libdir" to "libdirs" is not needed at all, so let's remove it. Signed-off-by: Tomi Valkeinen --- build/premake4.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/build/premake4.lua b/build/premake4.lua index 808e78fa..d9c3a249 100644 --- a/build/premake4.lua +++ b/build/premake4.lua @@ -18,7 +18,6 @@ solution "CppSharp" location (builddir) objdir (builddir .. "/obj/") targetdir (libdir) - libdirs { libdir } debugdir (bindir) -- startproject "Generator" From 7021d7ca01777d7e8b181e43149b65d3183b5b27 Mon Sep 17 00:00:00 2001 From: Tomi Valkeinen Date: Mon, 5 May 2014 14:41:14 +0300 Subject: [PATCH 05/11] build: use path.join() for objdir use path.join() to set objdir. Signed-off-by: Tomi Valkeinen --- build/premake4.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/premake4.lua b/build/premake4.lua index d9c3a249..20f70cf4 100644 --- a/build/premake4.lua +++ b/build/premake4.lua @@ -16,7 +16,7 @@ solution "CppSharp" flags { common_flags } location (builddir) - objdir (builddir .. "/obj/") + objdir (path.join(builddir, "obj")) targetdir (libdir) debugdir (bindir) From 0fb1bacae7bea63744876eda89cc800c260ce78a Mon Sep 17 00:00:00 2001 From: Tomi Valkeinen Date: Mon, 5 May 2014 09:51:29 +0300 Subject: [PATCH 06/11] CppParser: Fix compilation warning Fix the following warning: warning: backslash-newline at end of file [enabled by default] Signed-off-by: Tomi Valkeinen --- src/CppParser/Helpers.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/CppParser/Helpers.h b/src/CppParser/Helpers.h index 3e9d1f44..c1d191e6 100644 --- a/src/CppParser/Helpers.h +++ b/src/CppParser/Helpers.h @@ -55,4 +55,5 @@ #define DEF_STRING(klass, name) \ const char* klass::get##name() { return name.c_str(); } \ - void klass::set##name(const char* s) { name = s; } \ No newline at end of file + void klass::set##name(const char* s) { name = s; } + From 6d09688241d772e4af5c5e14f0e5ed900b84fc25 Mon Sep 17 00:00:00 2001 From: Tomi Valkeinen Date: Tue, 6 May 2014 19:36:14 +0300 Subject: [PATCH 07/11] ParserGen: fix compilation warning Fix the following warning: ParserGen.cs(208,26): warning CS0618: `CppSharp.AST.Declaration.Ignore' is obsolete: `Replace set by ExplicitlyIgnore(). Replace get by GenerationKind == GenerationKind.None.' Signed-off-by: Tomi Valkeinen --- src/CppParser/Bindings/ParserGen.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CppParser/Bindings/ParserGen.cs b/src/CppParser/Bindings/ParserGen.cs index 0a8447fc..3966949b 100644 --- a/src/CppParser/Bindings/ParserGen.cs +++ b/src/CppParser/Bindings/ParserGen.cs @@ -156,7 +156,7 @@ namespace CppSharp public override bool VisitFunctionDecl(Function function) { - if (function.Ignore) + if (function.GenerationKind == GenerationKind.None) return false; if (function.Parameters.Any(param => IsStdType(param.QualifiedType))) From dc5e9616954d29cd22667c044bb2edb2b8d5e8f0 Mon Sep 17 00:00:00 2001 From: Tomi Valkeinen Date: Wed, 7 May 2014 09:00:33 +0300 Subject: [PATCH 08/11] build: add os.is_linux() Add function to detect if running on linux. Signed-off-by: Tomi Valkeinen --- build/Helpers.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/build/Helpers.lua b/build/Helpers.lua index 099e427d..32169d0a 100644 --- a/build/Helpers.lua +++ b/build/Helpers.lua @@ -31,6 +31,10 @@ function os.is_windows() return os.is("windows") end +function os.is_linux() + return os.is("linux") +end + function string.starts(str, start) return string.sub(str, 1, string.len(start)) == start end From 1053aa79d16d1427fec4e9a5baef67553446da60 Mon Sep 17 00:00:00 2001 From: Tomi Valkeinen Date: Wed, 7 May 2014 22:59:44 +0300 Subject: [PATCH 09/11] ParserGen: print what is being generated Signed-off-by: Tomi Valkeinen --- src/CppParser/Bindings/ParserGen.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/CppParser/Bindings/ParserGen.cs b/src/CppParser/Bindings/ParserGen.cs index 3966949b..30e25ccd 100644 --- a/src/CppParser/Bindings/ParserGen.cs +++ b/src/CppParser/Bindings/ParserGen.cs @@ -121,12 +121,12 @@ namespace CppSharp public static void Main(string[] args) { - Console.WriteLine("Generating the C++/CLI parser bindings..."); + Console.WriteLine("Generating the C++/CLI parser bindings for Windows..."); ConsoleDriver.Run(new ParserGen(GeneratorKind.CLI, "i686-pc-win32", CppAbi.Microsoft)); Console.WriteLine(); - Console.WriteLine("Generating the C# parser bindings..."); + Console.WriteLine("Generating the C# parser bindings for Windows..."); ConsoleDriver.Run(new ParserGen(GeneratorKind.CSharp, "i686-pc-win32", CppAbi.Microsoft)); @@ -136,6 +136,7 @@ namespace CppSharp // of libcxx since the one provided by the Mac SDK is not compatible with a recent // Clang frontend that we use to parse it. + Console.WriteLine("Generating the C# parser bindings for OSX..."); ConsoleDriver.Run(new ParserGen(GeneratorKind.CSharp, "i686-apple-darwin12.4.0", CppAbi.Itanium)); } From 5b474483feaf0948e41e89c7e2a6287c886c0763 Mon Sep 17 00:00:00 2001 From: Tomi Valkeinen Date: Thu, 8 May 2014 08:39:52 +0300 Subject: [PATCH 10/11] AST: Fix compilation warning Fix the following warning by removing the new keyword: src/AST/Type.cs(230,25): warning CS0109: The member `CppSharp.AST.PointerType.IsReference' does not hide an inherited member. The new keyword is not required Signed-off-by: Tomi Valkeinen --- src/AST/Type.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/AST/Type.cs b/src/AST/Type.cs index 2e95a3fe..3442c033 100644 --- a/src/AST/Type.cs +++ b/src/AST/Type.cs @@ -232,7 +232,7 @@ namespace CppSharp.AST RVReference } - public new bool IsReference + public bool IsReference { get { @@ -756,4 +756,4 @@ namespace CppSharp.AST T VisitPackExpansionType(PackExpansionType packExpansionType, TypeQualifiers quals); T VisitCILType(CILType type, TypeQualifiers quals); } -} \ No newline at end of file +} From 480a06f26058030f671f74ced6bdc22d5f002bef Mon Sep 17 00:00:00 2001 From: Tomi Valkeinen Date: Tue, 13 May 2014 14:41:29 +0300 Subject: [PATCH 11/11] Generator: Remove DriverOptions.Is32Bit DriverOptions.Is32Bit is used to decide whether to use 4 or 8 byte pointer size in VTable calculations. Instead of having a settable Is32Bit property, use TargetInfo.PointerWidth for this. This allows us to remove the whole Is32Bit property, and the IS_64_BIT define. Signed-off-by: Tomi Valkeinen --- build/premake4.lua | 5 +---- .../Generators/CSharp/CSharpTextTemplate.cs | 14 +++++++------- src/Generator/Options.cs | 7 ------- 3 files changed, 8 insertions(+), 18 deletions(-) diff --git a/build/premake4.lua b/build/premake4.lua index 20f70cf4..6d30be19 100644 --- a/build/premake4.lua +++ b/build/premake4.lua @@ -30,9 +30,6 @@ solution "CppSharp" configuration "windows" defines { "WINDOWS" } - configuration "x64" - defines { "IS_64_BIT" } - configuration {} if string.starts(action, "vs") then @@ -55,4 +52,4 @@ solution "CppSharp" if string.starts(action, "vs") and os.is_windows() then include (srcdir .. "/Parser/Parser.lua") - end \ No newline at end of file + end diff --git a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs index f97d191a..c357463e 100644 --- a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs +++ b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs @@ -1404,14 +1404,14 @@ namespace CppSharp.Generators.CSharp var vfptr = @class.Layout.VFTables[tableIndex]; var size = vfptr.Layout.Components.Count; WriteLine("var vfptr{0} = Marshal.AllocHGlobal({1} * {2});", - tableIndex, size, Driver.Options.Is32Bit ? 4 : 8); + tableIndex, size, Driver.TargetInfo.PointerWidth / 8); WriteLine("_NewVTables[{0}] = vfptr{0}.ToPointer();", tableIndex); for (int entryIndex = 0; entryIndex < vfptr.Layout.Components.Count; entryIndex++) { var entry = vfptr.Layout.Components[entryIndex]; var offsetInBytes = VTables.GetVTableComponentIndex(@class, entry) - * (Driver.Options.Is32Bit ? 4 : 8); + * (Driver.TargetInfo.PointerWidth / 8); if (entry.Ignore) WriteLine("*(void**)(vfptr{0} + {1}) = *(void**)(native->vfptr{0} + {1});", tableIndex, offsetInBytes); @@ -1434,14 +1434,14 @@ namespace CppSharp.Generators.CSharp // reserve space for the offset-to-top and RTTI pointers as well var size = entries.Count; - WriteLine("var vfptr{0} = Marshal.AllocHGlobal({1} * {2});", 0, size, Driver.Options.Is32Bit ? 4 : 8); + WriteLine("var vfptr{0} = Marshal.AllocHGlobal({1} * {2});", 0, size, Driver.TargetInfo.PointerWidth / 8); WriteLine("_NewVTables[0] = vfptr0.ToPointer();"); for (int i = 0; i < entries.Count; i++) { var entry = entries[i]; var offsetInBytes = VTables.GetVTableComponentIndex(@class, entry) - * (Driver.Options.Is32Bit ? 4 : 8); + * (Driver.TargetInfo.PointerWidth / 8); if (entry.Ignore) WriteLine("*(void**)(vfptr0 + {0}) = *(void**)(native->vfptr0 + {0});", offsetInBytes); else @@ -2104,17 +2104,17 @@ namespace CppSharp.Generators.CSharp private void GenerateVirtualTableFunctionCall(Method method, Class @class) { string delegateId; - Write(GetVirtualCallDelegate(method, @class, Driver.Options.Is32Bit, out delegateId)); + Write(GetVirtualCallDelegate(method, @class, out delegateId)); GenerateFunctionCall(delegateId, method.Parameters, method); } public string GetVirtualCallDelegate(Method method, Class @class, - bool is32Bit, out string delegateId) + out string delegateId) { var virtualCallBuilder = new StringBuilder(); var i = VTables.GetVTableIndex(method, @class); virtualCallBuilder.AppendFormat("void* slot = *(void**) ((({0}.Internal*) {1})->vfptr0 + {2} * {3});", - @class.BaseClass.Name, Helpers.InstanceIdentifier, i, is32Bit ? 4 : 8); + @class.BaseClass.Name, Helpers.InstanceIdentifier, i, Driver.TargetInfo.PointerWidth / 8); virtualCallBuilder.AppendLine(); string @delegate = GetVTableMethodDelegateName((Method) method.OriginalFunction); diff --git a/src/Generator/Options.cs b/src/Generator/Options.cs index c1a1d93a..3f1d617f 100644 --- a/src/Generator/Options.cs +++ b/src/Generator/Options.cs @@ -44,11 +44,6 @@ namespace CppSharp Encoding = Encoding.ASCII; CodeFiles = new List(); - - Is32Bit = true; -#if IS_64_BIT - Is32Bit = false; -#endif } // General options @@ -173,8 +168,6 @@ namespace CppSharp get { return GeneratorKind == GeneratorKind.CLI; } } - public bool Is32Bit { get; set; } - public List CodeFiles { get; private set; } public readonly List DependentNameSpaces = new List(); public bool MarshalCharAsManagedChar { get; set; }