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 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/build/premake4.lua b/build/premake4.lua index 808e78fa..6d30be19 100644 --- a/build/premake4.lua +++ b/build/premake4.lua @@ -16,9 +16,8 @@ solution "CppSharp" flags { common_flags } location (builddir) - objdir (builddir .. "/obj/") + objdir (path.join(builddir, "obj")) targetdir (libdir) - libdirs { libdir } debugdir (bindir) -- startproject "Generator" @@ -31,9 +30,6 @@ solution "CppSharp" configuration "windows" defines { "WINDOWS" } - configuration "x64" - defines { "IS_64_BIT" } - configuration {} if string.starts(action, "vs") then @@ -56,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/build/premake5 b/build/premake5-osx similarity index 100% rename from build/premake5 rename to build/premake5-osx 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 +} 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/ParserGen.cs b/src/CppParser/Bindings/ParserGen.cs index 0a8447fc..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)); } @@ -156,7 +157,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))) 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 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; } + 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" } 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; }